Skip to content

fix(pre-M3): root page 500 — guard auth() for Clerk test mode#11

Merged
parva3105 merged 2 commits intomasterfrom
fix/pre-m3-root-500
Mar 20, 2026
Merged

fix(pre-M3): root page 500 — guard auth() for Clerk test mode#11
parva3105 merged 2 commits intomasterfrom
fix/pre-m3-root-500

Conversation

@parva3105
Copy link
Copy Markdown
Owner

Root cause

`await auth()` was called unguarded in the `app/page.tsx` Server Component. In Clerk test mode (`pk_test_*` keys), Clerk throws when the dev-browser cookie is absent — crashing the page with a 500.

`/login` and `/signup` were unaffected because they are `'use client'` components that never call `auth()` server-side.

Fix

Wrap `auth()` in `try/catch`. If it throws, `role` stays `undefined` and the landing page renders normally. The `redirect()` calls remain outside the try-catch so Next.js's `NEXT_REDIRECT` error still propagates correctly.

let role: string | undefined;
try {
  const { sessionClaims } = await auth();
  role = (sessionClaims?.metadata as { role?: string })?.role;
} catch {
  // Fall through — show landing page
}
if (role === "agency") redirect("/dashboard");

Checklist

  • npm run typecheck — zero errors
  • npm run lint — zero errors (3 pre-existing react-hook-form warnings)
  • / will now render the landing page for unauthenticated visitors
  • Authenticated users with a valid role JWT are still redirected server-side

🤖 Generated with Claude Code

…Clerk test mode

Clerk test-mode (pk_test_* keys) throws when auth() is called in a Server
Component without the dev-browser cookie. Separated auth() into a guarded
try-catch so role is undefined on failure, letting the landing page render
normally. redirect() calls remain outside the try-catch so NEXT_REDIRECT
still propagates correctly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 20, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
project-alpha Ready Ready Preview, Comment Mar 20, 2026 8:57pm

…ver component use

buttonVariants was defined in components/ui/button.tsx which is 'use client'
(needed for ButtonPrimitive from @base-ui/react/button). Turbopack enforces
the RSC rule: calling a 'use client' function from a Server Component throws
at runtime. Fix: move the CVA config to lib/button-variants.ts (no 'use client')
and re-import it in button.tsx, app/page.tsx, and signup-role-picker.tsx.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@parva3105 parva3105 merged commit b687352 into master Mar 20, 2026
1 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant