Repository navigation
TP1: a database per user on Workers - #2
Merged
Merged
Conversation
notrab/turso-per-user-starter (main 590144a; no licence anywhere — no LICENSE file, no package.json licence, no README section, none on GitHub) in apps/web: Next.js 16.3.8 (upstream's 14; OpenNext 1.20 refuses 15.5) with React 19 and Clerk 7 (auth() awaited, auth.protect(), middleware.ts as Next 16's proxy.ts), built by next build --webpack and then @opennextjs/cloudflare (standalone output, the static-assets incremental cache) into one Worker with Static Assets, 1.94 MiB gzipped — inside Workers Free. Turso stays the SaaS it is upstream: each user's database (md5 of their Clerk id) is created through Turso's Platform API (@tursodatabase/api 1.9, its global fetch) from the owner's seed database in the default group, and the dashboard's server actions read and write it through drizzle over @libsql/client/web (libSQL's HTTP protocol; the Node entry carries a native module) with the group's token; @libsql/isomorphic-ws is traced whole (outputFileTracingIncludes), because the build traces libSQL — a Next server-external package — for Node and the Worker resolves its workerd export. app/utils.ts became lib/turso.ts (the Turso switch, the Platform API calls), lib/db.ts (the user's database) and lib/todos.ts (the queries). Clerk's webhook verifies Svix's signature against the raw body before parsing it (upstream verified a re-serialised req.json()), creates a database only for a signed user.created, and answers 503 without its secret (upstream threw). Clerk is connected when the build had both its keys (lib/clerk.ts, clerk-auth-starter's switch); without them there is no ClerkProvider, the proxy passes requests through, and sign-up, sign-in and the dashboard say Clerk is not connected yet. Turso's four values are read per request: without them the dashboard names what is missing and /dump.sql answers 503, never a 500 (upstream's Platform API client threw on import); the authenticated layout is force-dynamic so no build bakes that answer in. The build runs without the Worker's six keys (env -u; told of Clerk's secret key only that it exists, CLERK_SECRET_KEY_SET) and tooling/wire/worker-secrets.mjs hands them to the Worker as Worker secrets from a deploy lane; the component reads all seven as optional Orun secret refs. Inter is self-hosted, the Open Graph image is served from public/, the site's name one seam (SITE_NAME in app/site.ts, the landing's heading and title), metadataBase NEXT_PUBLIC_SITE_URL, and the landing's "GitHub Repo" and the user menu's "Star repository" the site's own source link. /api/health is the deploy's smoke (ok unless a Clerk-built Worker lacks CLERK_SECRET_KEY; Clerk, Turso and the webhook reported). tests/web: identity and the Clerk switch, Turso's connection and its Platform API calls against a local stand-in (the template's create request), the webhook against Svix-signed deliveries (forged, stale, altered and re-serialised refused), the todo queries on a real libSQL file through the libsql client's file mode, seeded from migrations/ and from dump.sql, and the secret push. typecheck, lint, test and build are green; wrangler dev serves the site not connected, and — with made-up Clerk and Turso keys — answers a signed-out visitor with Clerk's middleware and creates a user's database at a stand-in of the Platform API from a signed webhook. Co-Authored-By: Claude <noreply@anthropic.com> Orun-Task: TP-2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
notrab/turso-per-user-starter (main 590144a; no licence anywhere — no LICENSE file, no package.json licence, no README section, none on GitHub) in apps/web: Next.js 16.3.8 (upstream's 14; OpenNext 1.20 refuses 15.5) with React 19 and Clerk 7 (auth() awaited, auth.protect(), middleware.ts as Next 16's proxy.ts), built by next build --webpack and then @opennextjs/cloudflare (standalone output, the static-assets incremental cache) into one Worker with Static Assets, 1.94 MiB gzipped — inside Workers Free. Turso stays the SaaS it is upstream: each user's database (md5 of their Clerk id) is created through Turso's Platform API (@tursodatabase/api 1.9, its global fetch) from the owner's seed database in the default group, and the dashboard's server actions read and write it through drizzle over @libsql/client/web (libSQL's HTTP protocol; the Node entry carries a native module) with the group's token; @libsql/isomorphic-ws is traced whole (outputFileTracingIncludes), because the build traces libSQL — a Next server-external package — for Node and the Worker resolves its workerd export. app/utils.ts became lib/turso.ts (the Turso switch, the Platform API calls), lib/db.ts (the user's database) and lib/todos.ts (the queries). Clerk's webhook verifies Svix's signature against the raw body before parsing it (upstream verified a re-serialised req.json()), creates a database only for a signed user.created, and answers 503 without its secret (upstream threw). Clerk is connected when the build had both its keys (lib/clerk.ts, clerk-auth-starter's switch); without them there is no ClerkProvider, the proxy passes requests through, and sign-up, sign-in and the dashboard say Clerk is not connected yet. Turso's four values are read per request: without them the dashboard names what is missing and /dump.sql answers 503, never a 500 (upstream's Platform API client threw on import); the authenticated layout is force-dynamic so no build bakes that answer in. The build runs without the Worker's six keys (env -u; told of Clerk's secret key only that it exists, CLERK_SECRET_KEY_SET) and tooling/wire/worker-secrets.mjs hands them to the Worker as Worker secrets from a deploy lane; the component reads all seven as optional Orun secret refs. Inter is self-hosted, the Open Graph image is served from public/, the site's name one seam (SITE_NAME in app/site.ts, the landing's heading and title), metadataBase NEXT_PUBLIC_SITE_URL, and the landing's "GitHub Repo" and the user menu's "Star repository" the site's own source link. /api/health is the deploy's smoke (ok unless a Clerk-built Worker lacks CLERK_SECRET_KEY; Clerk, Turso and the webhook reported). tests/web: identity and the Clerk switch, Turso's connection and its Platform API calls against a local stand-in (the template's create request), the webhook against Svix-signed deliveries (forged, stale, altered and re-serialised refused), the todo queries on a real libSQL file through the libsql client's file mode, seeded from migrations/ and from dump.sql, and the secret push. typecheck, lint, test and build are green; wrangler dev serves the site not connected, and — with made-up Clerk and Turso keys — answers a signed-out visitor with Clerk's middleware and creates a user's database at a stand-in of the Platform API from a signed webhook.
🤖 Generated with Claude Code