Cloudflare-native auth + email (drop Clerk + Resend) + account email change - #47
Open
unforced wants to merge 1 commit into
Open
Cloudflare-native auth + email (drop Clerk + Resend) + account email change#47unforced wants to merge 1 commit into
unforced wants to merge 1 commit into
Conversation
…email change Migrate the auth and email layers onto Cloudflare primitives and add a self-serve email-change flow. Also bundles the in-flight Summer 2026 cohort funnel work that shared the working tree. Auth (Clerk -> magic-link): - Stateless HMAC-signed session cookies (lib/session.ts); single-use, hashed, 20-min magic tokens (lib/magic-link.ts, migration 0025). - getUser via session; findOrCreateUser keyed on email with a synthetic clerk_id (no users-table rebuild). Removed clerkMiddleware, Clerk webhook, Clerk JS embed, middleware/auth.ts. - LVB's own OAuth 2.1 server (MCP connector) unaffected -- session-backed. Email (Resend -> Cloudflare Email Service): - env.EMAIL send_email binding; from hello@learnvibe.build; text/plain part; parseFromAddress + htmlToText; List-Unsubscribe on broadcasts. - Magic-link email restyled. Removed resend SDK + audience mirror + the defunct /admin/interests audience UI. Account email change (new): - /settings/email request -> confirm link to the NEW address. Confirming requires BOTH the link AND a matching session (prevents typo/hostile-address account takeover); single-use, uniqueness re-checked at confirm, old address notified (migration 0026, lib/email-change.ts). Hardening from an adversarial review: awaited + binding-guarded magic-link send (no silent auth dead-end), atomic single-use tokens, SESSION_SECRET guarded before token burn, session signature decode fails closed. Removed deps: resend, @clerk/backend, @hono/clerk-auth. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Migrates LVB's auth and email layers onto Cloudflare primitives, adds a self-serve email-change flow, and removes the Clerk + Resend dependencies. All of this is already deployed to production and verified end-to-end (this PR records the working tree). Also bundles the in-flight Summer 2026 cohort funnel work that shared the tree.
Auth: Clerk → magic-link
lib/session.ts) — no sessions table, one users-by-id read per request.lib/magic-link.ts, migration0025). Atomic single-use claim (UPDATE … WHERE used=0 … RETURNING).getUserreads the session;findOrCreateUserkeys on email and stores a syntheticclerk_idso the NOT NULL UNIQUE column survives without a table rebuild.clerkMiddleware, the Clerk webhook, the Clerk JS embed,middleware/auth.ts.Email: Resend → Cloudflare Email Service
env.EMAILsend_emailbinding; senderhello@learnvibe.build(onboarded in CF dashboard, DKIM/SPF/DMARC).text/plainpart;parseFromAddress+htmlToTexthelpers;List-Unsubscribe(mailto) + visible unsubscribe line on broadcasts.resendSDK, the audience mirror (resend-audience.ts), and the now-defunct "audience sync" UI on/admin/interests.Account email change (new)
POST /settings/email→ confirmation link to the new address.GET /settings/email/verifyrequires both the link and a matching session (prevents a mistyped/hostile address from taking over an account), re-checks uniqueness at confirm, updatesusers.email, and notifies the old address (migration0026,lib/email-change.ts).Hardening (adversarial review — 11 findings, all fixed or tracked)
SESSION_SECRETguarded before the token is consumed; session signature decode fails closed; tightenedsendEmailto a single recipient.Removed deps
resend,@clerk/backend,@hono/clerk-auth. Deleted unusedCLERK_SECRET_KEY/CLERK_WEBHOOK_SECRETsecrets.Verification
tscclean. Live-tested on prod: magic-link sign-up/sign-in (email delivered via CF, inbox not spam), session persistence, single-use enforcement, OAuth/MCP connector, and the full email-change matrix (no-session → sign-in, wrong-account → 403, happy path, replay → 410, all POST validations).Follow-ups (tracked, low/future)
RESEND_API_KEYsecret is now dead — can be deleted on request.🤖 Generated with Claude Code