fix(auth): stamp session cookies onto redirect response after OAuth exchange - #833
Merged
Conversation
…xchange Next.js does not propagate cookies() mutations into NextResponse.redirect() automatically — the Set-Cookie headers were missing, so the browser never received session cookies despite Supabase confirming a successful login. Root cause confirmed via Supabase auth logs: /token returned 200 (login) on every Google OAuth and magic-link attempt, but users remained signed out. Changes: - Collect cookies in pendingCookies[] during setAll(), then explicitly stamp them onto the NextResponse.redirect() before returning - Reject //host double-slash bypass in `next` param open-redirect guard - Move cookieStore await after the oauthError early-return (avoid unnecessary work) - Log exchangeCodeForSession errors for production debugging - Replace filter/forEach with for..of to avoid intermediate array allocation - Await signInWithProvider() in LoginDrawer so errors surface via notifyError toast instead of being silently swallowed
|
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
cookies()mutations intoNextResponse.redirect()— session tokens were never delivered to the browser despite Supabase returning a valid token, so OAuth and magic-link logins silently failedpendingCookies[]array duringsetAll(), then explicitly stamp each one onto theNextResponse.redirect()response object before returningnextparam against//hostopen-redirect bypass; use plainorigin(fromnew URL(request.url)) for all redirects — avoids cross-origin cookie mismatches on preview deployments that would occur withNEXT_PUBLIC_SITE_URL, and avoids the open-redirect risk of trustingx-forwarded-hostawaitthesignInWithProvidercall so errors surface via the existingnotifyErrortoast instead of being swallowedTest plan
/?error=auth_callback_errornextparam (//evil.com) → redirected to/not external host