Skip to content

jwt.verify() returns numeric payload claims as strings #1042

Description

@The-FirstMoon

Explanation:
I hope you doing great guys
When I use "verify()" in Typescript it is going to return string for everything even the one was a number in the "sign()" object payload.

Summary of the issue:
When signing a JWT with a numeric id claim, jwt.verify() appears to return the claim as a string instead of a number.

A small copy of my code:
const token = jwt.sign(
{ id: 67 },
secret
);
const decoded = jwt.verify(token, secret) as { id: number };
console.log(typeof decoded.id);
Expected behavior:
number
Actual behavior:
string

I checked the value before calling "jwt.sign()" and was confirmed to be a number .

Environment
Node.js: v20.20.2
Package: [jsonwebtoken, @types/jsonwebtoken]
Package version: [^9.0.3, ^9.0.10]
OS: window 11

I hope you have a great day.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions