Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions .baseline/product/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,21 @@ key is public by design, and RLS is what protects the data.
## Custom domain

The app answers on workers.dev from its first deploy. To serve it on your
own domain, attach the domain to the Worker in Cloudflare (Workers & Pages β†’
`supabase-starter-web-prod` β†’ Settings β†’ Domains & Routes), then make it
prod's `app_origin` in `infra/terraform/supabase/terraform/main.tf` and merge
β€” the apply owns the project's Auth Site URL and redirect allow-list.
own domain:

1. Attach the domain to the Worker in Cloudflare (Workers & Pages β†’
`supabase-starter-web-prod` β†’ Settings β†’ Domains & Routes).
2. Set `SITE_URL: https://<your-domain>` under `environments.prod.env` in
`intent.yaml`. It is the one setting for the product's origin: the app's
build bakes it into its absolute links (the Open Graph and Twitter
images), and the supabase apply makes it the project's Auth Site URL and
redirect allow-list.
3. Redeploy both: change the last line of `apps/web/component.yaml` and of
`infra/terraform/supabase/component.yaml` (`# orun: redeploy …`) in the
same pull request β€” a change to `intent.yaml` alone plans nothing.

The apply owns the project's Auth URLs: an edit in the Supabase dashboard is
undone by the next apply.

## CI

Expand Down
10 changes: 6 additions & 4 deletions BOOTSTRAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,12 @@ orun new --blueprint repo-blueprint.yaml \
- **Tables**: the protected page's tutorial creates `notes` with row-level
security on and per-user policies. Every table in `public` needs RLS β€”
the publishable key is public by design.
- **Custom domain**: attach it to the Worker in Cloudflare, then make it
prod's Auth Site URL in the product's supabase root (its README, "Custom
domain"). There is no domain phase: attaching a domain needs zone
permissions the brokered `workers-deploy` token does not carry.
- **Custom domain**: attach it to the Worker in Cloudflare, then set
`SITE_URL` under the environment's `env:` in the product's `intent.yaml` β€”
the app's absolute links and the project's Auth Site URL both follow it β€”
and redeploy web and supabase (the product's README, "Custom domain").
There is no domain phase: attaching a domain needs zone permissions the
brokered `workers-deploy` token does not carry.
- **Refresh the record**: re-run `--phase 02-docs`; it is idempotent, and it
records whether sign-up asks for confirmation.

Expand Down
14 changes: 9 additions & 5 deletions ai/context/operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,14 @@ Caveats that matter:
project): edit the template and run `pnpm run wire:fixture`. The deploy
lanes render the real one in their own job tree; never commit a real
project's URL or key.
- Supabase Auth sends its links (password recovery, and confirmation when it
is on) to the Worker's workers.dev origin β€” the supabase root sets it from
its `workersDevSubdomain` parameter, and owns it: an edit in the dashboard
is undone by the next apply. On a custom domain, change it there (below).
- The product's origin is ONE setting. Unset, it is the environment's
workers.dev URL (`<repo>-web-<env>.<subdomain>.workers.dev`); with a custom
domain, `SITE_URL` under the environment's `env:` in `intent.yaml`. The
app's build bakes it into its absolute links (the Open Graph and Twitter
images), and the supabase apply makes it Auth's Site URL and redirect
allow-list, where Supabase sends its links (password recovery, and
confirmation when it is on). The apply owns those Auth settings: an edit in
the dashboard is undone by the next apply.

## Auth and email

Expand Down Expand Up @@ -152,7 +156,7 @@ orun integrations list --org <ws> --json && orun cloud check --org <ws>
| require email confirmation | SMTP first, then `authEmailConfirmation: "true"` (above) |
| add a table | create it with `enable row level security` and `auth.uid()` policies (above); the day the product has migrations, Lumen's `packages/db` + `db-migrate` is the shape, reading `SUPABASE_DB_URL` |
| redeploy without a change | edit the last line of the component's `component.yaml` (`# orun: redeploy <reason> <stamp>`) and merge β€” it is a deploy trigger, nothing reads it |
| serve a custom domain | attach it to the Worker in Cloudflare, then make it prod's `app_origin` in `infra/terraform/supabase/terraform/main.tf` and merge β€” the apply owns Auth's Site URL and redirect allow-list, so a dashboard edit would be undone |
| serve a custom domain | attach it to the Worker in Cloudflare, set `SITE_URL` under `environments.prod.env` in `intent.yaml`, and touch the redeploy line of both `apps/web/component.yaml` and `infra/terraform/supabase/component.yaml` in the same PR (an `intent.yaml` change alone plans nothing) |
| headless credentials | `ORUN_TOKEN` (workspace-scoped) + `GITHUB_TOKEN` |

The deployment record is the bootstrap's `02-docs` phase. Re-running it (the
Expand Down
10 changes: 7 additions & 3 deletions apps/web/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ import { ThemeProvider } from "next-themes";
import "./globals.css";
import { SITE_NAME } from "@/lib/site";

const defaultUrl = process.env.VERCEL_URL
? `https://${process.env.VERCEL_URL}`
: "http://localhost:3000";
// The product's public origin, which the Open Graph and Twitter images'
// absolute URLs resolve against. Not upstream's: it read VERCEL_URL, which no
// Cloudflare build has, so every deployed page pointed its images at
// localhost. Baked in at build β€” component.yaml's buildCommand sets it from
// the environment's SITE_URL (a custom domain), else its workers.dev URL, the
// same origin the Supabase project's Auth sends its links to.
const defaultUrl = process.env.NEXT_PUBLIC_SITE_URL || "http://localhost:3000";

export const metadata: Metadata = {
metadataBase: new URL(defaultUrl),
Expand Down
4 changes: 0 additions & 4 deletions apps/web/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { DeployButton } from "@/components/deploy-button";
import { EnvVarWarning } from "@/components/env-var-warning";
import { AuthButton } from "@/components/auth-button";
import { Hero } from "@/components/hero";
Expand All @@ -18,9 +17,6 @@ export default function Home() {
<div className="w-full max-w-5xl flex justify-between items-center p-3 px-5 text-sm">
<div className="flex gap-5 items-center font-semibold">
<Link href={"/"}>{SITE_NAME}</Link>
<div className="flex items-center gap-2">
<DeployButton />
</div>
</div>
{!hasEnvVars ? (
<EnvVarWarning />
Expand Down
4 changes: 0 additions & 4 deletions apps/web/app/protected/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { DeployButton } from "@/components/deploy-button";
import { EnvVarWarning } from "@/components/env-var-warning";
import { AuthButton } from "@/components/auth-button";
import { ThemeSwitcher } from "@/components/theme-switcher";
Expand All @@ -19,9 +18,6 @@ export default function ProtectedLayout({
<div className="w-full max-w-5xl flex justify-between items-center p-3 px-5 text-sm">
<div className="flex gap-5 items-center font-semibold">
<Link href={"/"}>{SITE_NAME}</Link>
<div className="flex items-center gap-2">
<DeployButton />
</div>
</div>
{!hasEnvVars ? (
<EnvVarWarning />
Expand Down
10 changes: 9 additions & 1 deletion apps/web/component.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,15 @@ spec:
# tree, from this environment's wiring document, so the Worker's vars and
# the URL and key `next build` inlines are the real project's; dev
# verifies with the fixture and has no wiring.
buildCommand: if [ "${ORUN_ENVIRONMENT}" != dev ]; then node ../../tooling/wire/live.mjs --template wrangler.template.jsonc --out wrangler.jsonc --components supabase --env "${ORUN_ENVIRONMENT}"; fi && pnpm exec turbo run build --filter=@app/web
#
# The product's public origin (the Open Graph and Twitter image links are
# absolute): the environment's SITE_URL when intent.yaml sets one (a
# custom domain), else its workers.dev URL β€” the same origin the supabase
# root gives the project's Auth as its Site URL. The subdomain is written
# out rather than read from ${WORKERS_DEV_SUBDOMAIN}: the composition
# exports that to the smoke step only, so the build would see it empty.
# ${ORUN_ENVIRONMENT} the runner sets for every step.
buildCommand: if [ "${ORUN_ENVIRONMENT}" != dev ]; then node ../../tooling/wire/live.mjs --template wrangler.template.jsonc --out wrangler.jsonc --components supabase --env "${ORUN_ENVIRONMENT}"; fi && NEXT_PUBLIC_SITE_URL="${SITE_URL:-https://supabase-starter-web-${ORUN_ENVIRONMENT}.your-workers-subdomain.workers.dev}" pnpm exec turbo run build --filter=@app/web

# Smoke: the home page renders, signed-out header included, and
# /api/health answers ok β€” the project's Auth reachable with the key this
Expand Down
25 changes: 0 additions & 25 deletions apps/web/components/deploy-button.tsx

This file was deleted.

7 changes: 4 additions & 3 deletions docs/phases/01-product.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,15 @@ main and reads the order off it: `supabase β†’ web`.
org `SUPABASE_ORG_ID` names, with a generated database password; then,
once the project reports `ACTIVE_HEALTHY`, its API keys are read and its
Auth is set β€” Site URL and redirect allow-list
`https://<reponame>-web-<env>.<subdomain>.workers.dev`, email
confirmation off. Its outputs are lease-published as `WIRING_SUPABASE`
`https://<reponame>-web-<env>.<subdomain>.workers.dev` (or the
environment's `SITE_URL`), email confirmation off. Its outputs are lease-published as `WIRING_SUPABASE`
(the URL and the publishable key), `SUPABASE_PROJECT_REF`,
`SUPABASE_DB_PASSWORD` and `SUPABASE_DB_URL`. A new project takes five to
seven minutes to come up.
2. **web** β€” installs, re-renders `wrangler.jsonc` from this environment's
wiring document, builds with OpenNext (`next build` inlines the same URL
and key into the browser bundle), deploys `<reponame>-web-<env>`, and
and key into the browser bundle, and the same origin Auth was given into
the pages' absolute image links), deploys `<reponame>-web-<env>`, and
smoke-tests it: the home page, and `/api/health`, which answers only when
the project's Auth answers the key the build inlined.

Expand Down
14 changes: 12 additions & 2 deletions infra/terraform/supabase/terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,23 @@ variable "authEmailConfirmation" {

# --- Locals ---

# The product's own origin when the environment has a custom domain: SITE_URL
# under its `env:` in intent.yaml, which the runner exports to this job as it
# does to the app's build (apps/web/component.yaml) β€” one setting, so Auth's
# links and the app's absolute URLs name the same origin. Empty when unset.
data "external" "site_url" {
program = ["bash", "-c", "jq -n --arg url \"$${SITE_URL:-}\" '{url: $url}'"]
}

locals {
supabase_org_id = var.supabaseOrgId
supabase_region = var.supabaseRegion
project_name = "${var.repo}-${var.environment}"
# The environment's Worker, as apps/web/component.yaml names it:
# <repo>-web-<env> on the account's workers.dev subdomain.
app_origin = "https://${var.repo}-web-${var.environment}.${var.workersDevSubdomain}.workers.dev"
# <repo>-web-<env> on the account's workers.dev subdomain β€” unless SITE_URL
# names the environment's custom domain.
worker_origin = "https://${var.repo}-web-${var.environment}.${var.workersDevSubdomain}.workers.dev"
app_origin = coalesce(trimsuffix(data.external.site_url.result.url, "/"), local.worker_origin)
}

# --- Generate database password ---
Expand Down
6 changes: 6 additions & 0 deletions intent.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ environments:
env:
BASE_DOMAIN: supabase-starter.example.com

# SITE_URL, set under an environment's `env:`, is the product's public
# origin there β€” the one its Open Graph and Twitter image links are built
# on and the one the Supabase project's Auth sends its links to. Unset, it
# is the environment's workers.dev URL. Set it once a custom domain answers
# for the environment (README, "Custom domain"); the next deploy of
# apps/web and the next apply of infra/terraform/supabase pick it up.
stage:
description: Deployed on every merge to main, before prod.
url: https://supabase-starter-web-stage.your-workers-subdomain.workers.dev
Expand Down
2 changes: 1 addition & 1 deletion specs/epics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ folder is the adoption; the merge creates the epic in the workspace.

| Epic | Cluster | Status | What it is |
|------|---------|--------|------------|
| [`supabase-starter/`](./supabase-starter/) | **SS** | πŸ”„ SS4 in review | Vercel's Next.js and Supabase Starter, equivalent in code and function, on Cloudflare Workers with the Supabase project provisioned by Orun β€” and an Orun baseline that instantiates it in one landing (SS4) |
| [`supabase-starter/`](./supabase-starter/) | **SS** | πŸ”„ SS5 in review | Vercel's Next.js and Supabase Starter, equivalent in code and function, on Cloudflare Workers with the Supabase project provisioned by Orun β€” and an Orun baseline that instantiates it in one landing (SS4, `baseline-v1`) |

As-built β‰  intent: what shipped lives in each epic's `IMPLEMENTATION-STATUS.md`.
41 changes: 40 additions & 1 deletion specs/epics/supabase-starter/IMPLEMENTATION-STATUS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ the code departed from `design.md` or from the upstream template.
| SS1 β€” the starter on Workers | βœ… Shipped | [#2](https://github.com/sourceplane/supabase-starter/pull/2) |
| SS2 β€” the Supabase project from Terraform | βœ… Shipped (validated; apply gated on a linked workspace) | [#3](https://github.com/sourceplane/supabase-starter/pull/3) |
| SS3 β€” ready to instantiate | βœ… Shipped | [#4](https://github.com/sourceplane/supabase-starter/pull/4) |
| SS4 β€” a baseline | πŸ”„ In review (SS-5) | this branch, `claude/blissful-ptolemy-c5ajf8` |
| SS4 β€” a baseline | βœ… Shipped, tagged `baseline-v1` | [#5](https://github.com/sourceplane/supabase-starter/pull/5) |
| SS5 β€” the product's own origin | πŸ”„ In review (SS-6) | this branch, `claude/blissful-ptolemy-c5ajf8` |

## Departures from the upstream template

Expand Down Expand Up @@ -149,3 +150,41 @@ check`; `terraform fmt`, `init -backend=false` and `validate` on the root.
Not verified: a Terraform apply (so neither the brokered OAuth token's reach
to the API-keys and Auth-config endpoints nor `ACTIVE_HEALTHY` polling), a
live deploy, a live bootstrap, and real email delivery (SS-I).

## SS5 β€” the product's own origin (SS-6)

Two defects `baseline-v1` shipped in every product:

- **The image links named localhost.** `app/layout.tsx` built `metadataBase`
from `VERCEL_URL`, which no Cloudflare build has, so `og:image` and
`twitter:image` on every deployed page were `http://localhost:3000/…`.
`metadataBase` is now `NEXT_PUBLIC_SITE_URL`, which `component.yaml`'s
buildCommand bakes in: the environment's `SITE_URL` when `intent.yaml` sets
one, else `https://<repo>-web-<env>.<subdomain>.workers.dev` β€” written out
in the command (the rename rewrites the worker name and the subdomain),
because the composition exports `WORKERS_DEV_SUBDOMAIN` to the smoke step
only. Baked at build rather than read from the request (`headers()` in
`generateMetadata`), because the pages are prerendered (`cacheComponents`):
a request-time origin would have made every static page dynamic.
- **The header offered "Deploy to Vercel"**, cloning upstream's example to
Vercel. `components/deploy-button.tsx` is gone, and so is its use in the
home page and the protected layout. The tutorial's Vercel-only step
(`sign-up-user-steps.tsx`, shown only when `VERCEL_ENV` is set) never
renders on Cloudflare and is left as upstream wrote it.

One origin, one setting: the supabase root reads the same `SITE_URL` (the
runner exports an environment's `env:` to every job of it) and makes it
Auth's Site URL and redirect allow-list, falling back to the same workers.dev
URL β€” so a custom domain is `SITE_URL` plus a redeploy of both components.
The rename's upstream list drops the deploy link and the demo URL, which
nothing in the tree carries any more.

### Verified (SS5)

The repository's checks; `testing/rebrand.test.sh`, `leak.test.sh` and
`placement.test.sh` (the product's build bakes its own origin, Auth's Site
URL follows SITE_URL, no Vercel clone link in the app); `e2e.test.sh` at
v2.78.4, which now asserts the served home page's `og:image` and
`twitter:image` start with the stage Worker's origin, that both images are
served, and that no "Deploy to Vercel" appears; `terraform validate` on the
root, and the origin it computes with and without `SITE_URL`.
5 changes: 3 additions & 2 deletions specs/epics/supabase-starter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ The upstream code stays the code: the `@supabase/ssr` server/browser clients, th

| Field | Value |
|-------|-------|
| Status | βœ… SS0–SS3 shipped (#1–#4) Β· πŸ”„ SS4 β€” a baseline (SS-5) in review. Supabase apply and live deploy gated on a linked workspace |
| Cluster | **SS** (SS0–SS4) |
| Status | βœ… SS0–SS4 shipped (#1–#5; SS4 tagged `baseline-v1`) Β· πŸ”„ SS5 β€” the product's own origin (SS-6) in review. Supabase apply and live deploy gated on a linked workspace |
| Cluster | **SS** (SS0–SS5) |
| Owner(s) | `apps/web` (the app) Β· `tests/web` (proxy tests) Β· `infra/terraform/supabase` (the project) |
| Builds on | `lumen` conventions β€” the `supabase` Terraform root and the orun-secrets wiring; `cirrus-baseline` conventions for the repository shape |
| Upstream | [vercel/next.js `examples/with-supabase`](https://github.com/vercel/next.js/tree/canary/examples/with-supabase) |
Expand All @@ -34,3 +34,4 @@ The upstream code stays the code: the `@supabase/ssr` server/browser clients, th
| SS2 β€” the Supabase project from Terraform | `infra/terraform/supabase`, the app's `secretEnv` and `dependsOn` | the root plans; the wiring keys match the template |
| SS3 β€” ready to instantiate | README, as-built status | a reader can run, test, preview and deploy it |
| SS4 β€” a baseline | card, build document, rename, bootstrap tooling, the product's README and context pack, tests | a new product goes from nothing to live on stage and prod in one landing, signing users up on its first deploy; Baseline CI green |
| SS5 β€” the product's own origin | `metadataBase` from the build's `NEXT_PUBLIC_SITE_URL`, SITE_URL read by the supabase root too, the Deploy to Vercel button removed | the served pages' image links name the product's origin; no Vercel call to action |
7 changes: 7 additions & 0 deletions specs/epics/supabase-starter/epic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,10 @@ spec:
- "the tutorial's table has row-level security keyed on auth.uid(); the e2e proves each user reads only their own rows and anon none"
- "Baseline CI is green: contract tests, the blueprint read by the pinned orun, the leak gate, the offline bootstrap and the product's plans, and the end-to-end tier"
tasks: [SS-5]
- name: "SS5 β€” the product's own origin"
exitCriteria:
- "every page's og:image and twitter:image are absolute URLs on the product's own origin β€” the environment's workers.dev URL, or its SITE_URL β€” never localhost"
- "SITE_URL is one setting: the build's metadataBase and the Supabase project's Auth Site URL both follow it"
- "the product offers its visitors no Deploy to Vercel button"
- "the e2e tier asserts both on the served home page"
tasks: [SS-6]
Loading
Loading