fix: auto-merge Google email alias accounts at login#1861
Merged
Conversation
Users in countries where googlemail.com was the default (e.g. Germany) can end up with two accounts for the same mailbox. This caused a member who paid via gmail.com to see no subscription when logging in with googlemail.com. - Detect all Google domain aliases (gmail.com, googlemail.com, googlemail.co.uk, gmail.co.uk) at login via getGoogleEmailAliases() - Auto-merge the duplicate into the current session user, with atomic alias-claim to prevent concurrent-login race conditions - Show a green "Accounts merged" banner on success, fall back to manual merge banner if the auto-merge fails - Admin link-customer endpoint now syncs membership_tier and stripe_subscription_id alongside other subscription fields Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add UNIQUE(LOWER(email)) index on user_email_aliases to prevent two users from claiming the same alias concurrently - Roll back alias claim if mergeUsers fails so retry works on next login - Broaden NOT EXISTS check to skip emails claimed by any user - Remove unconfirmed gmail.co.uk from alias set Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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
gmail.comandgooglemail.comaccounts (same inbox) are automatically merged when they log in. Uses atomic alias-claim to prevent race conditions on concurrent logins.membership_tierandstripe_subscription_id: Previously these fields were missed when manually linking a Stripe customer, leaving orgs without proper tier entitlements.normalizeEmail()andgetGoogleEmailAliases()handle all Google domain variants (gmail.com,googlemail.com,googlemail.co.uk,gmail.co.uk).Context
Triggered by escalation #195/#196: Lina Georg paid $250 for Professional membership via
twiegle@gmail.combut logs in withtwiegle@googlemail.com(common in Germany wheregooglemail.comwas the default). Her login account showed no subscription.Root cause: WorkOS created two separate user accounts for what Google treats as the same mailbox.
How it works
getGoogleEmailAliases()checks all Google domain variantsINSERT ... ON CONFLICT DO NOTHING(prevents concurrent-login race)mergeUsers()transactionTest plan
email-domain.test.ts— 14 tests covering all alias variants🤖 Generated with Claude Code