Node-jsonwebtoken: Error: invalid expiresIn,jwtid option for number payload

Created on 19 Mar 2017  路  2Comments  路  Source: auth0/node-jsonwebtoken

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())
        }
    );

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 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.

All 2 comments

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!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

prevostc picture prevostc  路  4Comments

ehartford picture ehartford  路  3Comments

dwelle picture dwelle  路  3Comments

cope picture cope  路  4Comments

usamamashkoor picture usamamashkoor  路  4Comments