Skip to content

feat(auth): link Google sign-in to an existing account with the same email - #3964

Open
hjescalona wants to merge 3 commits into
CapSoftware:mainfrom
Solomedia:feat/google-account-linking
Open

hjescalona wants to merge 3 commits into
CapSoftware:mainfrom
Solomedia:feat/google-account-linking

Conversation

@hjescalona

@hjescalona hjescalona commented Nov 9, 2026 •

Copy link
Copy Markdown

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: the signIn callback refuses Google profiles whose email_verified is not true and sends them to /login?error=GoogleEmailUnverified, which the login page explains. Sign-up rules are unchanged: CAP_ALLOWED_SIGNUP_DOMAINS still 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; only email_verified: true passes the callback). The existing Google sign-in cases now pass a verified profile, as Google always sends one. Also ran oauth-sign-in-errors, sso-login-pages and nextauth-email-route.

RetriggerView in GreptileConfidence 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_verified is true.

  • Google sign-in now connects verified emails to existing Cap accounts.
  • Google verification errors keep a safe destination for sign-in to resume.

Reviews (2) · Last reviewed commit: "fix(auth): keep the return path when Goo..." · Reviewed by Greptile

…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.
@vercel

vercel Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

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

1 Skipped Deployment
Project Deployment Actions Updated
cap-status Skipped Skipped Nov 19, 2026 5:08pm UTC

Comment thread packages/database/auth/auth-options.ts Resolved
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.
@hjescalona

Copy link
Copy Markdown
Author

@greptileai review

Both findings from the previous review are addressed in 25a352e: the unverified-email redirect now keeps the safe next path (covered in sso-auth-route.test.ts), and the redundant test comment is removed.

@vercel
vercel Bot temporarily deployed to Preview – cap-status November 19, 2026 17:08 Inactive

This branch was previously deployed

1 inactive deployment
Preview – cap-status — 9c9915d2 Deployed Nov 19, 2026 by vercel[bot]
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