镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

fix(auth): match member invitations by case-insensitive email - #538

Open
maruf1020 wants to merge 1 commit into
theam:mainfrom
maruf1020:fix/member-invite-email-case
Open

maruf1020 wants to merge 1 commit into
theam:mainfrom
maruf1020:fix/member-invite-email-case

Conversation

@maruf1020

Copy link
Copy Markdown

Problem

POST /v1/members looks up the invited user with eq(users.email, body.email) (case-sensitive) and stores the email exactly as typed. GitHub sign-in (routes/auth.ts) admits invitations by comparing lower(users.email) with lower-cased verified emails, and facility instance bootstrap lower-cases the owner email.

Failure scenario: an admin invites jane@acme.com, then re-invites Jane@Acme.com to change her role. A second users row and membership are created instead of updating the first. If Jane has not signed in yet, her GitHub sign-in then fails with 403 identity_conflict ("Multiple Facility users match verified GitHub emails"); if she has, the role change silently lands on an orphan account.

Fix

Export the existing normalizedEmail from auth/identity-provider.ts so invitations use the same normalization as sign-in: the lookup is lower(users.email) = normalized, and new invitations are stored lower-cased.

Tests

  • test/identity-provider.test.ts: it.each case for normalizedEmail.
  • test/member-invite-email.integration.test.ts (new): a re-invite in different case updates the same user (one users row, new role); a legacy mixed-case row is still matched; a new invitation is stored lower-cased.

Commands run

biome check (2.5.2) on the changed files: clean. Vitest/tsc not run locally (no Postgres/Docker test stack here); relying on CI.

GitHub login admits an invitation by comparing lower(users.email) with the
lower-cased verified GitHub emails, and `facility instance bootstrap`
stores the owner email in lower case. POST /v1/members instead looked the
invited address up with an exact, case-sensitive match and stored it as
typed. Re-inviting someone as "Jane@Example.com" after "jane@example.com"
therefore created a second user with a second membership instead of
updating the existing one, and while neither account was linked to GitHub
that person's login failed with identity_conflict ("Multiple Facility users
match verified GitHub emails").

Normalize the invited address the same way login does, look it up with
lower(email), and store new invitations in lower case.

This branch has not been deployed

No deployments
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