Skip to content

getClaims is raising a generic Error for expired token #2394

@ex0ns

Description

@ex0ns

Describe the bug

When calling getClaims with a given JWT, the expiration is checked using validateExp which throws Error("JWT has expired").

if (!options?.allowExpired) {
// Reject expired JWTs should only happen if jwt argument was passed
validateExp(payload.exp)
}

I believe we could/should catch a rethrow a AuthInvalidJwtError instead (this would be a breaking change though)

happy to make this small change if it makes sense

Library affected

auth-js

Reproduction

No response

Steps to reproduce

call getClaims on an expired token

System Info

System:
    OS: macOS 26.4.1
    CPU: (11) arm64 Apple M3 Pro
    Memory: 304.42 MB / 36.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 24.14.0 - /Users/ex0ns/.nvm/versions/node/v24.14.0/bin/node
    npm: 11.9.0 - /Users/ex0ns/.nvm/versions/node/v24.14.0/bin/npm
    pnpm: 11.0.9 - /Users/ex0ns/.nvm/versions/node/v24.14.0/bin/pnpm
    bun: 1.3.13 - /opt/homebrew/bin/bun
    Deno: 2.7.13 - /opt/homebrew/bin/deno
  Browsers:
    Chrome: 148.0.7778.179
    Firefox: 150.0.3
    Safari: 26.4

Used Package Manager

pnpm

Logs

No response

Validations

Metadata

Metadata

Assignees

Labels

auth-jsRelated to the auth-js library.bugSomething isn't working

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions