feat(auth): harden auth flow, extract context loader, enable local beta whitelist - #231
Merged
Conversation
…ta whitelist Auth: - Add server-side POST /logout that clears the httpOnly active_org_id cookie (client signOut can't), preventing the prior user's org leaking across sessions on a shared browser. - Extract the hooks.server.ts context-loading into src/lib/server/auth.ts (loadUserContext/applyUserContext + pure helpers); hook is now a thin orchestrator. Adds unit tests for the four identity branches and SSO. - Gate the /auth/callback domain auto-join on an actual SSO session, so a plain OAuth/magic-link signup whose email domain matches an org's SSO provider is no longer auto-joined to that org. - Cache positive beta-whitelist results in a short-TTL in-memory map to drop a per-request query on warm instances; authz context is never cached. Beta whitelist (local dev): - Document BETA_WHITELIST_ENABLED in .env.example and seed allow-listed emails in supabase/seed.sql so local mirrors deployed behavior. Other: - Point the marketing "Join Beta" button and the login page at /beta unconditionally (was host-gated to beta.threadline.systems), and surface a /beta link on the not-whitelisted error. - Resolve all svelte-check a11y/CSS warnings (aria-labels on icon buttons, label-vs-span on composite controls, keyboard-accessible color swatch, empty ruleset). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Summary
POST /logoutclears the httpOnlyactive_org_idcookie (the clientsignOutcan't), so the prior user's active org no longer leaks across sessions on a shared browser.hooks.server.tsintosrc/lib/server/auth.ts(loadUserContext/applyUserContext+ pure helpers); the hook is now a thin orchestrator. Adds 19 unit tests covering the four identity branches (system-admin / org-member / buyer / onboarding) and SSO enforcement. Semantics preserved./auth/callbacknow gates the domain-based auto-join on an actual SSO session (isSsoSession), so a plain OAuth/magic-link signup whose email domain happens to match an org's SSO provider is no longer auto-joined to that org.BETA_WHITELIST_ENABLEDdocumented in.env.exampleand allow-listed emails seeded insupabase/seed.sqlso local mirrors deployed behavior./betaunconditionally (was host-gated tobeta.threadline.systems, so it fell through to/logineverywhere else); the not-whitelisted error also surfaces a/betalink.svelte-checkwarnings (aria-labels on icon-only buttons,label→spanon composite controls, a keyboard-accessible color swatch, removed an empty CSS ruleset). No visual change.Why
Tightens the auth flow (logout hygiene, SSO auto-join), makes the most security-critical path testable, brings beta-whitelist parity to local dev, and clears accumulated lint/a11y debt on the branch.
Verification
bun run lintpasses (prettier + eslint)bun run checkpasses — 0 errors, 0 warningsbun run test:runpasses — 742 testsTest plan
active_org_idcookie is cleared and re-login lands in the right org.BETA_WHITELIST_ENABLED=true, a non-whitelisted email is bounced to/loginwith the "Join the private beta" link →/beta; a whitelisted email gets in./betaon localhost./onboarding, not auto-joined.Notes
getUser()→getClaims()(drops the per-request auth network call but is security-sensitive and depends on JWT signing-key setup) — can follow up if wanted.supabase/seed.sqlemails are local-only (seed is not applied to deployed envs).🤖 Generated with Claude Code