fix: resolve GitHub account email from /user/emails primary - #60
Merged
Conversation
Better Auth default prioritises /user.email (the public profile email), which routinely differs from the primary account email. Returning GitHub users then sign in with a different address and the planner creates a duplicate member. Resolve the email from /user/emails (primary + verified) via a getUserInfo override, matching the legacy omniauth-github integration. Fail soft when GitHub calls throw so a network error does not turn the OAuth callback into a 500.
mroderick
force-pushed
the
fix/github-primary-email
branch
from
August 6, 2026 18:29
f3f2398 to
cd6f8b3
Compare
mroderick
marked this pull request as ready for review
August 6, 2026 18:33
Collaborator
Author
Nothing like testing in the real world 💥 |
Collaborator
Author
|
Close and re-open to trigger CI |
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
Resolves the duplicate-signup bug in #59. Better Auth's default GitHub provider prioritises
/user.email(the public profile email), while the planner's legacy omniauth-github integration used the primary + verified address from/user/emails. For the same GitHub account these routinely differ, so returning GitHub users signed in with a different email and the planner created duplicate members + duplicate RSVPs.Adds a
getUserInfooverride on the GitHub social provider that resolves the account email from/user/emails(primary + verified), matching the legacy integration and the pre-existing member records.Changes
src/auth/github-provider.js(new): fetches/userand/user/emails; selects the primary + verified email first, falling back to the public profile email only when no primary is verified. Fails soft on network/HTTP errors (returnsnull, never throws) so a GitHub outage doesn't turn the callback into a 500.src/auth.js: wiresgetUserInfo: getGithubUserInfointo thegithubsocial provider.test/unit/github-provider.test.js(new): covers primary-verified preference over the public email, fallback paths, and the throw/no-throw error case.How to verify (manual)
GITHUB_CLIENT_ID/GITHUB_CLIENT_SECRETfor a GitHub account whose public profile email differs from its primary account email, then start the app (npm run dev)./user/emails), not the public profile email.Notes
This fixes future signups. The two existing duplicate members from the 2026-08-06 Berlin workshop are not merged here — that is a separate data-cleanup task.
Closes #59