fix(oauth-provider): omit given_name and family_name when the user has no name - #11201
Open
SibteProf wants to merge 1 commit into
Open
fix(oauth-provider): omit given_name and family_name when the user has no name#11201SibteProf wants to merge 1 commit into
SibteProf wants to merge 1 commit into
Conversation
…s no name
splitDisplayName took a plain string and called name.split(" ") on it. The
name column is nullable in practice, so resolving the given_name or
family_name claim for a user without a name threw a TypeError out of the
claim resolver, returning 500 from /userinfo and from the token endpoint
whenever an ID token was issued.
The adjacent name claim already resolves the same value with `?? undefined`,
so the null is expected in this module; only the split was unguarded. Accept
a nullish name and return no claims for it, which leaves both claims absent
rather than failing the whole response.
Closes better-auth#11193
SibteProf
requested review from
gustavovalverde
and removed request for
a team
September 7, 2026 13:41
|
@SibteProf is attempting to deploy a commit to the better-auth Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
|
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 #11193
The bug
splitDisplayNameinpackages/oauth-provider/src/standard-claims.tstakes a plainstringand immediately callsname.split(" "). Resolvinggiven_nameorfamily_namefor a user whose storednameis null throws aTypeErrorout of the claim resolver, surfacing as 500 from/userinfo, and from the token endpoint whenever an ID token is issued. Any client requesting theprofilescope for such a user hits it.Why this is a contract violation, not just bad data
userSchematypesnameasz.string(), so the null does not come from the type contract. It comes from how this module already treats the value:userNormalClaimsinuserinfo.tsdoes the same for the subject (sub: user.id ?? undefined). So the module already treats these fields as runtime-nullable — three claims resolve a missing value to an absent claim, and two dereference it one line later. That inconsistency is the defect: a claim the provider cannot resolve should be omitted, not fail the entire response including the claims that did resolve.The change
splitDisplayNamenow accepts a nullish name and returns no claims for it. It is a module-private helper, so no exported type changes andUser["name"]staysz.string()— the runtime guard is not being used to loosen the public type contract.Testing
New
packages/oauth-provider/src/standard-claims.test.tsexercises the resolvers directly: two-part and multi-part names, single word, blank,null, andundefined. Thenullandundefinedcases fail onmainwith the reportedTypeErrorand pass with this change.vitest packages/oauth-provider— 42 files, 948 tests passingpnpm typecheck— passingAI assistance
Disclosed per CONTRIBUTING: this change was AI-assisted (Claude Code) — the investigation, patch and tests were produced with it. I have reviewed the full diff myself and verified it locally by running the commands above. Happy to discuss any of it in review.
Summary by cubic
Fixes the OAuth provider so
given_nameandfamily_nameclaims are omitted for users with no name instead of failing the request. Previously, requesting theprofilescope for such a user returned 500 from/userinfoand from the token endpoint when an ID token was issued.splitDisplayNamenow accepts a nullish name and returns no claims.null, andundefinednames.Written for commit 2a264c8. Summary will update on new commits.