Skip to content

Conversation

@ephraimduncan
Copy link
Contributor

Summary

  • Wrap getSession() with React's cache() to memoize within a request
  • Update TRPC context to use shared getSession() instead of calling auth.api.getSession() directly

Problem

Sporadic TRPCError: UNAUTHORIZED errors on /dashboard due to race condition:

  1. Layout calls getSession() → cookie cache valid → passes
  2. TRPC context calls auth.api.getSession() → cookie cache expires → fails
  3. protectedProcedure throws UNAUTHORIZED

Solution

Memoize getSession() so both layout and TRPC share the same session result within each request.

Test plan

  • Deploy and monitor for UNAUTHORIZED errors on /dashboard
  • Verify dashboard loads correctly for authenticated users

Wrap getSession() with React's cache() and use it in TRPC context
to ensure layout and TRPC share the same session within a request.

Fixes sporadic UNAUTHORIZED errors when cookie cache expires mid-request.
@ephraimduncan ephraimduncan merged commit 3abafff into main Jan 26, 2026
3 of 4 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.

2 participants