Issue 1338
feat: Connect Google to an existing account from the account page
Back to our planDone
enhancementfrontendauthpriority: medium
Problem
A neighbor who already has an account with an email and password can't use the Google button with it. Signing in with Google never takes over an existing account by email alone, on purpose, so they are told to use their password. There is no way to connect Google to the account they have.
Proposed fix
- Connect right at sign-in (main way). When Google sign-in finds an account that already uses the
Google-verified email, it no longer just refuses. It shows a short page: "This email already has an
account. Enter your password once to connect Google." The neighbor enters the password there; on
success Google is attached to that account and they are signed in. Rules: the Google identity and
verified email wait in a short-lived (10 minutes), single-use pending record tied to the flow's
__Host-cookie, never in the page; the password check uses the normal sign-in path, its limits and lockout (#140) and the one fixed failure that doesn't say whether an account exists; the stored link is written only while the account has none; nothing is linked by email alone, and Google without the password never signs in to the existing account. - Connect from the account page (second way). A signed-in neighbor chooses "Connect Google" on
/account. It runs the same Google flow as sign-in, but as a link started from their session: the callback attaches the Google identity to that session's account and nothing else. - A recent password sign-in is required, checked when the flow starts and again when it finishes, using the same recent-sign-in rule as adding a passkey (one definition, reused). The flow's cookie is bound to the account that started it, so a callback can't attach Google to a different session's account.
- One Google identity, one account. A Google identity already on any account is refused, with a plain message; the stored link is written only while the account has none.
- Afterwards the Google button signs that neighbor in to the same account.
/accountshows that Google is connected. - Messages (catalog, brand voice): the connect-with-your-password page, its failure, and the Google-already-on-another-account refusal. The old "use your password" refusal goes away.
- Email: a short note that Google was connected, with what to do if it wasn't them (no link).
Existing work compared
- Searched: open and closed issues for link, Google, provider and account. #188 (closed) made Google sign-in and records that linking by email alone is refused; #501 prompts login for an existing email on forms, which is unrelated; #1316 manages passkeys on the same page.
- Native: Payload has no account linking. Library: the OAuth library already in use covers the protocol; the flow, binding and rules are our domain layer from #188.
- Our code: reuses #188's flow cookie, state and rate limits, the recent-sign-in check from #1314, and the UI kit. New work.
Acceptance criteria
Tests first.
- Not done: Use-case tests: linking needs a session and a recent password sign-in; an old session is refused at start and at finish; the account comes only from the session; a callback whose flow cookie belongs to another account is refused.
- Not done: At sign-in: Google with an email an account already uses leads to the password page, and only a correct password connects and signs in; a wrong password, an expired or replayed pending record, another flow's cookie, locked, unverified and agent accounts all get one fixed failure; Google alone never signs in to the existing account.
- Not done: The password page at 320, 430, 768, 1024, 1280 and 1920 px, light and dark; one full-width 44 px button on a phone.
- Not done: A Google identity that is already on any account is refused and nothing changes; the link is written only while empty.
- Not done: After linking, the Google button signs in to the same account (no new account is made).
- Not done: Component tests with axe: the Connect Google card and the connected state, messages announced.
- Not done: By hand with real Google: sign in with email and password, connect Google, sign out, sign in with Google and land on the same account.
- Not done:
/accountat 320, 430, 768, 1024, 1280 and 1920 px, light and dark: rows line up, nothing overflows. - Not done: The notification email names the time and carries no sign-in link.
- Not done: The accounts note and the Google sign-in record are updated in the same PR.
Files likely touched
src/modules/accounts/domain/(link rules),use-cases/(start and finish linking),data/src/app/(frontend)/auth/[provider]/(link purpose on the existing routes), a page for the password step, and the pending-link record indata/(single use, 10 minutes, purged hourly)src/modules/accounts/ui/(Connect Google card),src/platform/lib/messages/accounts.tssrc/app/(frontend)/account/page.tsx,src/modules/accounts/README.md
Must not touch
Password sign-in, sign-up, passkeys, and the rule that Google never links by email alone.
Owner direction
The owner asked (2026-11-20, voice) for the prompt at sign-in so neighbors don't need a hidden page, and to keep the account-page button as a second way.
Generated by Claude Code, opens in a new tab