I am trying to use the latest version of the module only I keep getting issues when trying to sign a token with the expiresIn and jwtid-ptions. Only keep getting the same error (see below) keeps complaining about number payload but why? The documents seem to suggest it can be a string. What am I doing wrong?
Error: invalid expiresIn,jwtid option for number payload
at Object.module.exports [as sign] (/Users/Development/Projects/xyz/backend/node_modules/jsonwebtoken/sign.js:81:22)
I am using the following code:
return jwt.sign(
payload, // This is the payload we want to put inside the token
process.env.TOKEN_SECRET || "oursecret", // Secret string which will be used to sign the token,
{
expiresIn: '2h', // let the token expire after 2 hours of creation
jwtid: identifier, // unique identifier (uuid.v4())
}
);
If you want to have as payload a number the JWT can't contain any claim in the payload, this is only supported for object payloads.
That's why exp and jti can not be added, thus you get a complain about your options expiresIn and jwtid which are requesting those claims to be added.
Ah right, now it's working. Quite confusing error message. Thank you!
Most helpful comment
If you want to have as payload a number the JWT can't contain any claim in the payload, this is only supported for object payloads.
That's why
expandjtican not be added, thus you get a complain about your optionsexpiresInandjwtidwhich are requesting those claims to be added.