Search code examples
javascriptjson-web-token

jsonwebtoken.sign() fails with expiresIn option set


I need to get a token by signing a user ID with JWT:

var token = jwt.sign(accounts[request.headers.login].id, privateKey, {expiresIn: 60});

Where id and privateKey are strings.

The error is Error: Uncaught error: "expiresIn" should be a number of seconds or string representing a timespan eg: "1d", "20h", 60. If I remove options object at all, it works, but without options I need to set.

The issue seems to be simple but I don't know how to fix it, what am I doing wrong?


Solution

  • https://www.npmjs.com/package/jsonwebtoken#jwtsignpayload-secretorprivatekey-options-callback

    payload could be an object literal, buffer or string. Please note that exp is only set if the payload is an object literal.