Skip to content

fix(apple): guard against unexpected user shape in profile callback#13417

Open
Nadav0077 wants to merge 1 commit intonextauthjs:mainfrom
Nadav0077:fix/apple-profile-user-shape
Open

fix(apple): guard against unexpected user shape in profile callback#13417
Nadav0077 wants to merge 1 commit intonextauthjs:mainfrom
Nadav0077:fix/apple-profile-user-shape

Conversation

@Nadav0077
Copy link
Copy Markdown

☕️ Reasoning

The Apple provider's profile callback in packages/core/src/providers/apple.ts assumes that whenever profile.user is truthy, it has the shape { name: { firstName, lastName } }.

That object comes from JSON.parse(params.user) in packages/core/src/lib/actions/callback/oauth/callback.ts, which performs no shape validation. Any JSON-valid value (a string, a number, null, or a partial object) ends up assigned to profile.user. When it is truthy but not the expected shape, profile.user.name.firstName throws a TypeError.

The error is swallowed upstream in getUserAndAccount's catch block, so the user just sees a silent sign-in failure with no useful diagnostic.

This change adds defensive optional chaining so the callback falls back to profile.email instead of throwing when the user payload is malformed or partial. No behavior change for the happy path.

🧢 Checklist

  • Documentation
  • Tests
  • Ready to be merged

🎫 Affected issues

None.

📌 Resources

@Nadav0077 Nadav0077 requested a review from ThangHuuVu as a code owner April 17, 2026 21:34
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 17, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
auth-docs Ready Ready Preview, Comment Apr 17, 2026 9:38pm
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
next-auth-docs Ignored Ignored Preview Apr 17, 2026 9:38pm

Request Review

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 17, 2026

@Nadav0077 is attempting to deploy a commit to the authjs Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Refers to `@auth/core` providers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant