Repository navigation
feat(auth): link Google sign-in to an existing account with the same email - #3964
Open
hjescalona wants to merge 3 commits into
Open
hjescalona wants to merge 3 commits into
hjescalona wants to merge 3 commits into
Conversation
…email
Someone who signed up with an email code, or was added by an admin,
got OAuthAccountNotLinked ("This email already has a Cap account")
when they later tried Sign in with Google. The Google provider now
allows email account linking, like OIDC and WorkOS.
Linking relies on Google having verified the address: the signIn
callback refuses Google profiles whose email_verified is not true and
sends them to /login?error=GoogleEmailUnverified, which the login page
explains.
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
The signIn callback can't see the request, so /login?error=GoogleEmailUnverified dropped the destination kept in the callback-url cookie. The email-code fallback then landed on /dashboard, and a mobile sign-in never handed off its session. The NextAuth route now adds the cookie's safe return path as next on that redirect, the same way SSO errors keep theirs. Also drops a test comment that only restated the code.
Author
|
@greptileai review Both findings from the previous review are addressed in 25a352e: the unverified-email redirect now keeps the safe |
This branch was previously deployed
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.
Someone who signed up with an email code (or was added by an admin) and later clicks Sign in with Google is refused with
OAuthAccountNotLinked("This email already has a Cap account. Sign in using your original sign-in method."), so Google never works for them.The Google provider now sets
allowDangerousEmailAccountLinking, as the OIDC and WorkOS providers already do. Linking relies on Google having verified the address, the same way the OIDC provider is gated: thesignIncallback refuses Google profiles whoseemail_verifiedis nottrueand sends them to/login?error=GoogleEmailUnverified, which the login page explains. Sign-up rules are unchanged:CAP_ALLOWED_SIGNUP_DOMAINSstill applies to new accounts, and blocked or disposable addresses are still refused.Tested with two new cases in
auth-options.test.ts(the Google provider allows linking; onlyemail_verified: truepasses the callback). The existing Google sign-in cases now pass a verified profile, as Google always sends one. Also ranoauth-sign-in-errors,sso-login-pagesandnextauth-email-route.

Confidence Score: 5/5
The PR appears safe to merge.Summary
Google sign-in can link to an existing account with the same email, but only when
email_verifiedistrue.Reviews (2) · Last reviewed commit: "fix(auth): keep the return path when Goo..." · Reviewed by Greptile