Skip to content

fix: resolve GitHub account email from /user/emails primary - #60

Merged
mroderick merged 1 commit into
mainfrom
fix/github-primary-email
Aug 7, 2026
Merged

fix: resolve GitHub account email from /user/emails primary#60
mroderick merged 1 commit into
mainfrom
fix/github-primary-email

Conversation

@mroderick

@mroderick mroderick commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

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 getUserInfo override 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 /user and /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 (returns null, never throws) so a GitHub outage doesn't turn the callback into a 500.
  • src/auth.js: wires getUserInfo: getGithubUserInfo into the github social 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)

  1. Add GITHUB_CLIENT_ID / GITHUB_CLIENT_SECRET for a GitHub account whose public profile email differs from its primary account email, then start the app (npm run dev).
  2. Complete a GitHub sign-in and confirm the resulting account's email is the primary account email (from /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

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
mroderick force-pushed the fix/github-primary-email branch from f3f2398 to cd6f8b3 Compare August 6, 2026 18:29
@mroderick
mroderick marked this pull request as ready for review August 6, 2026 18:33
@mroderick
mroderick requested a review from till August 6, 2026 18:33

@till till left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great find! 😁

@mroderick

Copy link
Copy Markdown
Collaborator Author

Great find! 😁

Nothing like testing in the real world 💥

@mroderick

Copy link
Copy Markdown
Collaborator Author

Close and re-open to trigger CI

@mroderick mroderick closed this Aug 7, 2026
@mroderick mroderick reopened this Aug 7, 2026
@mroderick
mroderick enabled auto-merge August 7, 2026 08:45
@mroderick
mroderick merged commit e9ffa8f into main Aug 7, 2026
7 checks passed
@mroderick
mroderick deleted the fix/github-primary-email branch August 7, 2026 08:45
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.

GitHub sign-in returns the public profile email instead of the OAuth primary email, breaking dedupe in the planner

2 participants