Repository navigation
Conversation
The GitHub provider's userinfo request crashed with `TypeError: Cannot read properties of undefined (reading 'email')` when /user/emails returned 200 with an empty array (bot, service, or org-restricted accounts). Guard the lookup so the email is left unset instead of throwing. Adds regression tests covering the empty-array case plus the existing primary/fallback behavior.
|
@pintu544 is attempting to deploy a commit to the authjs Team on Vercel. A member of the Team first needs to authorize it. |
This branch has not been deployed
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.
Closes #13495
Supersedes #12667 (idle since Feb 2025, no reviews)
Problem
When GitHub's
/user/emailsendpoint returns 200 with an empty array — which happens for bot accounts, service accounts, and org-restricted accounts — the GitHub provider crashes during sign-in with:The email fallback assumed there is always at least one email:
With
[], bothfind()andemails[0]areundefined, so reading.emailthrows.Fix
Guard the lookup — if there is no primary email and no first email, leave
profile.emailunset instead of throwing:Kept deliberately minimal: the
res.okhandling, the primary-first preference, and theemails[0]fallback are all untouched. The scope-check idea from the issue (skipping the/user/emailscall entirely whenuser:emailwasn't granted) would be a behavior change, so I'm noting it here as a possible follow-up rather than bundling it in.Tests
New:
packages/core/test/providers/github.test.ts(4 tests, vitest, fetch stubbed):/user/emailsarray → no throw, email stays unset (this one failed pre-fix with the exact TypeError from the issue)/user/emailsis never calledtest/providers/: 5/5 passing. ESLint and Prettier are clean on the changed files.tsc --noEmitreports only the 3 pre-existing errors that also appear on the untouched tree (missing build-generated type files), nothing new from this change.Manual verification
Reproduced it with a small script driving
userinfo.requestdirectly against stubbed fetch: pre-fix threwTypeError: Cannot read properties of undefined (reading 'email')on[]; post-fix returns the profile with the email unset, and the primary/fallback cases behave exactly as before.