From 2877a89528ac5a166ba493f501070f239d46dbf0 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 29 Oct 2026 02:06:41 +0000 Subject: [PATCH] SU3: ready to instantiate The README now covers how to run, test, preview and deploy the site, how to connect a sign-in provider (the Orun secrets, the callback URL and the nine providers the component carries refs for) and how the example maps from Vercel to this setup. The as-built status is updated to match: SU0 and SU1 shipped, what is proven and how, and every departure from the upstream example. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_019PcpNVpFBcbeiX3EHdXfmn --- README.md | 99 ++++++++++++++++--- specs/epics/README.md | 2 +- .../sveltekit-auth/IMPLEMENTATION-STATUS.md | 4 +- specs/epics/sveltekit-auth/README.md | 2 +- 4 files changed, 90 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 5bd1e02..d7736f7 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,97 @@ # sveltekit-auth -An Orunbase starter baseline, being built: Auth.js's [SvelteKit example](https://github.com/nextauthjs/sveltekit-auth-example) -on Cloudflare Workers + Static Assets through -[`@sveltejs/adapter-cloudflare`](https://svelte.dev/docs/kit/adapter-cloudflare), -on the Cirrus baseline conventions. ISC, © 2022-2024 Balázs Orbán -(`apps/web/LICENSE`). +Auth.js's [SvelteKit example](https://github.com/nextauthjs/sveltekit-auth-example) +— a home page, a sign-in page, a page only a signed-in visitor can read and a +sign-out, over [`@auth/sveltekit`](https://authjs.dev/reference/sveltekit) +with the example's 26 OAuth providers — running on **Cloudflare Workers + +Static Assets** through SvelteKit's own +[`@sveltejs/adapter-cloudflare`](https://svelte.dev/docs/kit/adapter-cloudflare). +It is being packaged as an **Orun baseline** that takes a new site from +nothing to live on stage and prod, in its own repository, under its own +name, in ONE landing. -Upstream: https://github.com/nextauthjs/sveltekit-auth-example +Sessions are the example's: Auth.js's encrypted JWT cookie, so there is no +database. Each provider is offered once its keys are stored as the site's +secrets, so the site goes live with none connected and its sign-in page +says what to connect; the AUTH_SECRET that seals the sessions is generated +on each environment's Worker by its first deploy, so nothing is typed. The +design, the milestones and the as-built status are in +[`specs/epics/sveltekit-auth`](specs/epics/sveltekit-auth/README.md). +ISC, © 2022-2024 Balázs Orbán (`apps/web/LICENSE`). + +## What is here + +| Surface | Where | +|---|---| +| The site's name (the home page's heading, every page's ``) | `apps/web/src/site.ts` | +| `/`, `/signin` (the connected providers, or what to connect), `/protected`, `/signout` | `apps/web/src/routes` | +| Auth.js, configured per request from the Worker's secrets | `apps/web/src/auth.ts`, `apps/web/src/hooks.server.ts`, `apps/web/src/server/env.ts` | +| The 26 providers and the keys each needs | `apps/web/src/server/providers.ts` | +| The header (who is signed in) and the footer | `apps/web/src/components` | +| The deploy step that gives each Worker its secrets | `tooling/wire/worker-secrets.mjs` | +| Adapter, Worker config, deploy contract | `apps/web/svelte.config.js`, `apps/web/wrangler.jsonc`, `apps/web/component.yaml` | +| Tests (the providers, the bindings, the site's name, the secret step) | `apps/web/src/**/*.test.ts` (vitest) | + +## Getting started -## Running it +```bash +pnpm install # runs `svelte-kit sync` +pnpm typecheck # svelte-check +pnpm lint # prettier --check +pnpm test # vitest +pnpm build # vite build → apps/web/.svelte-kit/cloudflare (_worker.js + the static output) +``` ```bash -pnpm install -pnpm typecheck && pnpm lint && pnpm test && pnpm build pnpm --filter @app/web secret:dev # a generated AUTH_SECRET in apps/web/.env (git-ignored) pnpm --filter @app/web dev # http://localhost:3000 pnpm --filter @app/web preview # wrangler dev over the built Worker ``` -A sign-in provider appears on `/signin` once its keys are in -`apps/web/.env` (`.env.example` lists them). The plan and the as-built -status are the epic in -[`specs/epics/sveltekit-auth`](specs/epics/sveltekit-auth/README.md). +Both read `apps/web/.env`; `.env.example` beside it, the example's own, +lists every key the site takes. Add a provider's keys there (GitHub: an OAuth app whose +callback is `http://localhost:3000/auth/callback/github`) and its button +appears on `/signin`. + +## Deploying + +The Orun pipeline (`.github/workflows/ci.yml`) plans nothing while +`intent.yaml` names the placeholder workspace `ws_CHANGE_ME`. Link the +repository to an Orun Cloud workspace (`orun cloud link`), set +`execution.state.workspace` to it, connect Cloudflare in the workspace, and +every merge to `main` then deploys `sveltekit-auth-web-stage`, then +`-prod`: built, its secrets pushed to the Worker (`wrangler secret bulk`, +the AUTH_SECRET generated on the first deploy and kept after), deployed and +smoke-tested on `/` and `/auth/session`. A pull request verifies the same +lanes and deploys nothing. A manual run of `ci.yml` (Run workflow on +`main`, or Orunbase's Deploy button) redeploys the components it names — +which is how a provider's newly stored keys reach the Worker. + +## Sign-in providers + +None is connected at first. A provider appears once **every** key it takes +is set: `AUTH_GITHUB_ID` + `AUTH_GITHUB_SECRET` for GitHub, and the same +shape for the others (Auth0 adds `AUTH_AUTH0_ISSUER`). Deployed, they are +optional Orun secrets per environment (`orun secrets set AUTH_GITHUB_ID +--env stage`), pushed to the Worker by its next deploy; the OAuth app's +callback URL is `<origin>/auth/callback/<provider>`. The component carries +secret refs for the nine providers upstream's `.env.example` names; the +keys of every other provider are in `apps/web/src/server/providers.ts`. + +## How it maps to Vercel + +| The example on Vercel | Here | +|---|---| +| `@sveltejs/adapter-auto` (→ `adapter-vercel`) | `@sveltejs/adapter-cloudflare`: the Worker at `.svelte-kit/cloudflare/_worker.js`, the static output beside it (`wrangler.jsonc`) | +| `"@auth/sveltekit": "latest"` | `1.11.3`, exact; SvelteKit, Svelte and Vite at upstream's versions, exact, and upstream's `cookie@0` override | +| `AUTH_SECRET` typed into Vercel's environment variables | generated on each environment's Worker by its first deploy (`tooling/wire/worker-secrets.mjs`), kept by every later one; an Orun secret of the same name wins | +| provider keys in Vercel's environment variables, all 26 providers always registered | optional Orun secrets pushed as Worker secrets; a provider is registered only when its keys are set, and `/signin` says what to connect | +| `$env/dynamic/private` from the platform's env | the Worker's bindings (`platform.env`), read per request; `.env` locally, as upstream, for `vite dev` and `wrangler dev` alike | +| sessions: Auth.js's JWT cookie | the same; no database | +| Deploy on push | Orun deploys `<repo>-web-{stage,prod}` on merge to `main` (`apps/web/component.yaml`), smoke-tested | + +## CI + +| Workflow | What it runs | Ships to a site | +|---|---|---| +| `ci.yml` | the Orun pipeline, and the only workflow a site carries: `orun plan --changed`, then one job per lane. A pull request runs the verify lanes (the site built and dry-deployed per environment, no secret pushed; they do not typecheck, lint or run the tests), except the bootstrap's own landings (`orun/BASE-*`), where `plan` alone is the check; a merge deploys stage → prod. It plans nothing while `intent.yaml` names the placeholder workspace `ws_CHANGE_ME`, as this repository does. A manual run (Orunbase's Deploy button, or Run workflow on `main`) plans the environment and components it names under the push-to-main trigger, so they deploy as a merge deploys them | yes | diff --git a/specs/epics/README.md b/specs/epics/README.md index 4d34ce9..1e7aa40 100644 --- a/specs/epics/README.md +++ b/specs/epics/README.md @@ -7,6 +7,6 @@ folder is the adoption; the merge creates the epic in the workspace. | Epic | Cluster | Status | What it is | |------|---------|--------|------------| -| [`sveltekit-auth/`](./sveltekit-auth/) | **SU** | In progress (SU1) | Auth.js's SvelteKit example — sign-in through any of 26 OAuth providers, each offered once its keys are stored, a protected page, JWT sessions with no database — on Cloudflare Workers + Static Assets, and an Orun baseline that instantiates it in one landing | +| [`sveltekit-auth/`](./sveltekit-auth/) | **SU** | In progress (SU3) | Auth.js's SvelteKit example — sign-in through any of 26 OAuth providers, each offered once its keys are stored, a protected page, JWT sessions with no database — on Cloudflare Workers + Static Assets, and an Orun baseline that instantiates it in one landing | As-built ≠ intent: what shipped lives in each epic's `IMPLEMENTATION-STATUS.md`. diff --git a/specs/epics/sveltekit-auth/IMPLEMENTATION-STATUS.md b/specs/epics/sveltekit-auth/IMPLEMENTATION-STATUS.md index 218a93f..ddf40e1 100644 --- a/specs/epics/sveltekit-auth/IMPLEMENTATION-STATUS.md +++ b/specs/epics/sveltekit-auth/IMPLEMENTATION-STATUS.md @@ -3,9 +3,9 @@ | Milestone | Status | Shipped in | |---|---|---| | SU0 — the spec | ✅ Shipped | [#1](https://github.com/sourceplane/sveltekit-auth/pull/1) | -| SU1 — the auth app on Workers | In progress | | +| SU1 — the auth app on Workers | ✅ Shipped | [#2](https://github.com/sourceplane/sveltekit-auth/pull/2) | | SU2 — the data | Not needed: JWT sessions persist nothing | — | -| SU3 — ready to instantiate | Not started | | +| SU3 — ready to instantiate | In progress | | | SU4 — a baseline | Not started | | ## What is proven, and how diff --git a/specs/epics/sveltekit-auth/README.md b/specs/epics/sveltekit-auth/README.md index c0a1035..d7fb392 100644 --- a/specs/epics/sveltekit-auth/README.md +++ b/specs/epics/sveltekit-auth/README.md @@ -13,7 +13,7 @@ the monorepo wrapper, tests and the deploy contract. | Field | Value | |-------|-------| -| Status | In progress — SU0 (#1) shipped; SU1 | +| Status | In progress — SU0 (#1), SU1 (#2) shipped; SU3 | | Cluster | **SU** (SU0, SU1, SU3, SU4; SU2, the data rung, is not needed) | | Owner(s) | `apps/web` · `tooling/wire/worker-secrets.mjs` | | Builds on | `sveltekit-boilerplate`: its scaffolding, its adapter-cloudflare build and its one-landing blueprint; the reference starters' `worker-secrets.mjs` |