fix(billing): withhold the free allowance from Gmail aliases of an existing account
Merged
WA
1d ago+32087+32087+01234567890123456789012345678901234567890123456789-14-14-01234567890123456789
Summary
- Gmail delivers every dot and
+tagvariant of an address (and itsgooglemail.comtwin) to one inbox, so a single person could registera.b@gmail.com,ab+1@gmail.com, … and get a fresh free allowance on each - A new account whose Gmail inbox another account (banned or not) already holds is now created with no free allowance — same "one free trial per identity" treatment returning deleted-account identities already get; signup itself is never refused, and paid plans and prepaid credit are untouched
- Applied on both allowance paths:
handleNewUserand thecreateUserStatsIfMissingfallback, via oneidentityHadFreeAllowancecheck - New
gmailMailbox()SQL expression in the schema (built onfoldedEmail) plus partial indexuser_gmail_mailbox_idx, so the lookup is an index probe instead of a scan ofuser; migration builds itCONCURRENTLY - Non-Gmail domains are never folded; fails open (logs, grants the allowance) on lookup error
Type of Change
- Bug fix
Testing
lib/users/gmail-alias.integration.tsagainst real Postgres withINTEGRATION_DB_PROVISION=migrate(exercises migration 0439): 5/5 pass. Disabling the check turns the 3 withholding tests red; one test asserts the plan usesuser_gmail_mailbox_idxlib/billing/core/usage.test.ts: 25/25 passcheck:migrations,check:file-names,check:test-patterns,check:comment-hygiene, biome on touched files;drizzle-kit generatereports no drift- Full type-check / audits / suite left to CI
Checklist
- Code follows project style guidelines
- Self-reviewed my changes
- Tests added/updated and passing (new tests pass the
test-auditauthoring gate) - No new warnings introduced
- I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)