fix: 409 for duplicate email connections#1586
Merged
tyler-dane merged 8 commits intomainfrom Mar 30, 2026
Merged
Conversation
tyler-dane
added a commit
to Muhammad-Nur-Alamsyah-Anwar/compass
that referenced
this pull request
Mar 30, 2026
* feat: consolidate emails upon duplicate to handle 409 conflicts * refactor: harden typing for google error handling * chore: reuse normalizeEmail util * fix: reduce extra user query * chore: remove dead error handling code * refactor: reuse findCanonicalCompassUser * fix(backend): update google auth mocks
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.

Note
Medium Risk
Touches authentication/session and account-linking paths (canonical user resolution and session replacement), which can affect login behavior and user mapping if incorrect. Changes are covered by expanded unit tests but still impact critical auth flows.
Overview
Fixes duplicate-account edge cases by introducing a canonical Compass user lookup (preferring
googleUserId, falling back to normalized email) and reusing that user across Google OAuth and email/password auth flows.Backend errors now support stable machine-readable
codes:BaseErrorcarries an optionalcode, the centralized error handler includes it in the client payload, and Google connect adds a new409case (GOOGLE_CONNECT_EMAIL_MISMATCH) plus a codedGOOGLE_ACCOUNT_ALREADY_CONNECTEDconflict.Web adds shared Zod error schemas in
core, genericparseApiError(...)plusparseGoogleConnectError(...), and updates the Google connect hook to show the server-provided message and keep the connect action available on typed failures; docs are updated to codify this shared error-contract pattern.Written by Cursor Bugbot for commit 4648306. This will update automatically on new commits. Configure here.