GitHub provider: emails[0] read unguarded throws on an empty /user/emails response
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 84/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- github, node.js, typescript
- Domain
- authentication
Research direction
Start with packages/core/src/providers/github.ts and the GitHub provider's userinfo.request fallback block. Run the linked reproduction with npm install and npm start to confirm the empty /user/emails response; the fix is complete when that response leaves profile.email unset, preserves the profile, and does not throw.
Written by the indexing model from the issue text.
Description
Provider type
GitHub
Environment
@auth/core0.41.3 (the version pinned bynext-auth5.0.0-beta.32), from npm- Node.js 24.17.0, standalone script, no framework involved
packages/core/src/providers/github.tsonmainas of 2026-09-09 still contains the same unguarded read, so this is not a 0.41.x-only regression
Reproduction URL
https://github.com/Nitjsefnie/next-auth-github-emails-repro
Describe the issue
When a GitHub profile has no public email, the GitHub provider's userinfo.request always calls the authenticated GET /user/emails endpoint. If that endpoint answers 200 with an empty list — which GitHub can return, e.g. for some bot/service and org-restricted accounts — the provider throws instead of returning the profile (providers/github.ts, the fallback block):
const emails: GitHubEmail[] = await res.json()
profile.email = (emails.find((e) => e.primary) ?? emails[0]).email
On an empty array emails.find(...) ?? emails[0] is undefined, so reading .email throws TypeError: Cannot read properties of undefined (reading 'email'). The request is also spent unconditionally: nothing checks whether the granted scope actually includes user:email before calling the endpoint.
Related: #13494 (same defect, closed by triage for a missing reproduction link — this issue supersedes it with the linked public repo).
How to reproduce
Clone the linked reproduction repository and run:
npm install
npm start
The script stubs fetch, returns an email-less /user profile and a 200 with [] from /user/emails, and calls the provider's userinfo.request — the same two responses GitHub serves an account with no email on file.
Observed output:
THREW: TypeError: Cannot read properties of undefined (reading 'email')
CALLS: https://api.github.com/user | https://api.github.com/user/emails
Expected behavior
An empty /user/emails response should leave profile.email unset — the profile itself is valid and the sign-in should proceed without an email, the same as when /user carries no email and the email endpoint is never consulted. The natural fix is to guard the index before reading .email:
const emails: GitHubEmail[] = await res.json()
const primary = emails.find((e) => e.primary) ?? emails[0]
if (primary) profile.email = primary.email
- Dominant language
- TypeScript
- Stars
- 28.4k
- Forks
- 4k
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from nextauthjs/next-auth
-
triage
Difficulty 1/5 Under an hour Newbie friendliness 88/100
nextauthjs/next-auth#13483 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
nextauthjs/next-auth#13475 ·
-
triage
Difficulty 1/5 Under an hour Newbie friendliness 88/100
nextauthjs/next-auth#13472 ·
-
bug triage
Difficulty 1/5 Under an hour Newbie friendliness 68/100
nextauthjs/next-auth#13204 ·
-
Typo: conepts Opentriage
Difficulty 1/5 Under an hour Newbie friendliness 62/100
nextauthjs/next-auth#12992 ·
All issues in nextauthjs/next-auth
Similar issues
-
calcite-components needs triage refactor
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Esri/calcite-design-system#15203 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 91/100
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficulty 1/5 Under an hour Newbie friendliness 95/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Automattic/studio#4908 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100