fix(auth): return AuthInvalidJwtError from getClaims for expired JWT#2395
Merged
Conversation
@supabase/auth-js
@supabase/functions-js
@supabase/postgrest-js
@supabase/realtime-js
@supabase/storage-js
@supabase/supabase-js
commit: |
d942277 to
cc1e9bc
Compare
o-santi
approved these changes
May 27, 2026
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.
Description
getClaimsis documented to return{ data, error }, but for expired JWTs it throws a plainError('JWT has expired'). The throw originates invalidateExp(lib/helpers.ts), which uses a genericError. The outer catch ingetClaimsonly convertsAuthErrorinstances to the return tuple, so the plainErrorescapes and breaks the documented contract.This PR wraps the single
validateExpcall site and rethrows asAuthInvalidJwtError, matching the pattern already used for invalid signatures a few lines below.What changed?
packages/core/auth-js/src/GoTrueClient.ts: wrappedvalidateExp(payload.exp)in a try/catch that rethrows asAuthInvalidJwtError. The outer catch then surfaces it as{ data: null, error }.packages/core/auth-js/test/GoTrueClient.test.ts: updated the expired-JWT test to assert on the{ data, error }return shape.validateExpinlib/helpers.tsis intentionally not changed, so the standalonevalidateExp(0)browser test continues to pass.Why was this change needed?
getClaims's signature-verification path already throwsAuthInvalidJwtErrorand returns it via{ data, error }. Expired tokens were the only error path violating the documented return type.Closes #2394
Screenshots/Examples
Before:
After:
Breaking changes
Small in practice. Anyone using the documented
const { data, error } = await getClaims()pattern is unaffected (and actually benefits, since their code was previously crashing on expired tokens). The only group impacted is callers who wrotetry/catchspecifically to catch the rawErrorthrown for expired tokens. Their migration is mechanical: move handling from the catch block toif (error). Error message is preserved andAuthInvalidJwtErroris already exported from@supabase/auth-js.Checklist
<type>(<scope>): <description>pnpm nx formatto ensure consistent code formattingAdditional notes
Landing as
fix(auth)rather thanfix(auth)!. The previous behavior contradicted the documented return type and the realistic blast radius is small (callers who built workarounds for the bug). Happy to relabel if reviewers prefer the louder signal.