Repository navigation
Resolve the signed-in user once per server render - #657
Merged
Merged
Conversation
A dashboard load resolved the user in the (app) layout, the dashboard layout, the header and the page, each a Supabase Auth getUser round trip (getClaims too on symmetric-key projects) before any HTML is sent; the page also fetched claims it discarded. getRequestUserWithMfa and getRequestClaims wrap them in React cache, so a render asks once. The viewer is still recorded on every call. Server components only: actions and route handlers keep getUserWithMfa on their own client. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QU2jrSHDpWbeLWT9Sv5YyJ
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
There was a problem hiding this comment.
All reported issues were addressed across 10 files
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QU2jrSHDpWbeLWT9Sv5YyJ
5 tasks done
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.
What & why
Server-side follow-up to the slow-network work (#654–#656). A dashboard render looked up the signed-in user four separate times before any HTML reached the browser:
(app)layoutgetOAuthMetadata)getAuthenticatedUser)generateMetadatatoo when?itemis set)Each lookup is a Supabase Auth
getUserround trip plus the MFA check.getClaimsis another round trip on projects with symmetric JWT keys, and the dashboard page fetched claims only to discard them.getRequestUserWithMfa()andgetRequestClaims()in@/lib/supabase/serverwrap those lookups in Reactcache, so one render makes one call. The viewer is still recorded on every call, because each caller may run in its own viewer frame.getAuthUserandgetOAuthMetadatanow go through them.getOAuthMetadatano longer takes a client.(app)layout, dashboard page,/savepage and dashboard layout use them directly.getUserWithMfaon their own client, so a sign-in or sign-out mid-request can never read a stale cached user. Every caller of the cached helpers is a page, a layout or a server component.getUserWithMfaruns once instead of four times. The middleware's own check is untouched.Checklist
captureServerException/ the error boundary, or N/A. N/A: no new paths.request-user.test.tsstands in for one render and asserts that three callers make onegetUserand onegetClaimscall, and that the viewer is recorded for each caller.user-metadata.test.tsis updated for the new signature.learnskill, or N/A. N/A.Notes
getClaimscalls to one.Generated by Claude Code