fix(auth): persist Google OAuth session on Studio (A1-fix) - #2007
Conversation
Align NextAuth JWT cookie verification with production secure cookies across proxy, billing, and studio security paths. Mount SessionProvider and render session-aware Studio nav after Google sign-in. Co-authored-by: Hayden <groupthinking@users.noreply.github.com>
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: Repository: groupthinking/EventRelay/.coderabbit.yaml Review profile: ASSERTIVE Plan: Advanced Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
SessionProvider triggers next-auth client logging that fetches /api/auth/_log without a base URL in jsdom, failing test-frontend. Co-authored-by: Hayden <groupthinking@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
It leaves a lint-triggering unused import and introduces avoidable site-wide authentication overhead.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Aligns NextAuth secure-cookie JWT verification and exposes authenticated identity controls in Studio.
Changes:
- Centralizes secure-cookie JWT handling across protected routes.
- Adds session-aware Studio sign-in/sign-out navigation.
- Adds focused authentication tests.
File summaries
| File | Description |
|---|---|
apps/web/src/proxy.ts |
Uses centralized JWT verification. |
apps/web/src/lib/studio/security.ts |
Aligns Studio owner authentication. |
apps/web/src/lib/billing/billing-context.ts |
Aligns billing session lookup. |
apps/web/src/lib/auth.ts |
Shares secure-cookie policy. |
apps/web/src/lib/auth-jwt.ts |
Adds centralized JWT helper. |
apps/web/src/lib/__tests__/auth-jwt.test.ts |
Tests secure-cookie decoding. |
apps/web/src/lib/__tests__/auth-config-source.test.ts |
Guards shared policy usage. |
apps/web/src/components/StudioAuthNavLink.tsx |
Adds session-aware navigation. |
apps/web/src/components/OneLoopStudio.tsx |
Integrates authentication control. |
apps/web/src/components/AuthSessionProvider.tsx |
Provides client session context. |
apps/web/src/components/__tests__/StudioAuthNavLink.test.tsx |
Tests navigation states. |
apps/web/src/app/layout.tsx |
Mounts the session provider. |
Review details
- Files reviewed: 13/13 changed files
- Comments generated: 3
- Review effort level: Balanced
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| {/* Keep JSON-LD away from preview scripts injected into the head. */} | ||
| <StructuredData /> | ||
| {children} | ||
| <AuthSessionProvider>{children}</AuthSessionProvider> |
| </Link> | ||
| } | ||
| /> | ||
| <Nav rightSlot={<StudioAuthNavLink />} /> |
|
|
||
| afterEach(() => { | ||
| cleanup(); | ||
| vi.restoreAllMocks(); |
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Snapshot WarningsEnsure that dependencies are being submitted on PR branches. Re-running this action after a short time may resolve the issue. See the documentation for more information and troubleshooting advice. Scanned FilesNone |
Canonical issue
Named cut A1-fix (AXIOM: OAuth/config session does not stick on https://uvai.io/studio after Google consent). Baseline:
e91f4a4/ #1973.Outcome
After Google sign-in for
garveyht@gmail.com, Studio shows a signed-in identity (email + Sign out) instead of a permanent Sign in link, and session-gated API routes can read the same JWT cookie NextAuth sets on callback.Root cause
Two separate gaps (not initiation-UX / not retry-button):
OneLoopStudioalways rendered a hardcoded Sign in link; the app had noSessionProvider/useSession, so post-OAuth UX looked unsigned even when/api/auth/sessioncould succeed.auth.tsforcesuseSecureCookieswhenNODE_ENV === 'production', butproxy.tsandbilling-context.tscalledgetToken()with NextAuth’s defaultsecureCookieheuristic (NEXTAUTH_URL+VERCELonly). On production-shaped hosts where that default is false while secure cookies are still set, middleware and billing would not see__Secure-next-auth.session-token(session-gated pack/enrich/deploy paths stay 401).Fix
nextAuthUseSecureCookies()+getNextAuthJwtFromRequest()inapps/web/src/lib/auth-jwt.tsand route all server JWT reads through it (auth.ts,proxy.ts,studio/security.ts,billing-context.ts).AuthSessionProviderin root layout; replace Studio nav Sign in stub withStudioAuthNavLink(email + Sign out when authenticated).Scope
/studio, aligned JWT cookie verification for gated/api/*.Verification
Automated (head
c16106593):Manual dogfood (after Vercel preview/production deploy — record
dpl_+ merge SHA here when READY):garveyht@gmail.com./studio→ nav shows garveyht@gmail.com and Sign out (no Sign in).__Secure-next-auth.session-tokenpresent foruvai.io.GET /api/auth/session(same browser) → JSON includesuser.email.https://www.youtube.com/watch?v=auJzb1D-fag, Run) → pack workbench populates; session-gated enrich (POST /api/extract-events) returns 200 when signed in (not 401).Google Cloud console (no change required if already live): authorized redirect URI must include
https://uvai.io/api/auth/callback/google. Production/api/auth/providersalready advertises that callback (verified 2026-09-18).Risk
NEXTAUTH_SECRET/ Google creds unchanged from baseline; worst case auth still fails closed on gated APIs.Production evidence
c16106593— update withdpl_…when preview/production is green.Agent handoff