jsonwebtoken.sign()失败,并设置了expiresIn选项 [英] jsonwebtoken.sign() fails with expiresIn option set
问题描述
我需要通过使用 JWT 签名用户ID来获得令牌:
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});
id
和privateKey
是字符串.
错误为Error: Uncaught error: "expiresIn" should be a number of seconds or string representing a timespan eg: "1d", "20h", 60
.
如果我完全删除了选项对象,则可以使用,但是没有选项我需要设置.
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?
推荐答案
https://www.npmjs.com/package/jsonwebtoken#jwtsignpayload-secretorprivatekey-options-callback
有效载荷可以是对象文字,缓冲区或字符串. 请注意,仅当有效载荷是对象文字时才设置exp.
payload could be an object literal, buffer or string. Please note that exp is only set if the payload is an object literal.
这篇关于jsonwebtoken.sign()失败,并设置了expiresIn选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!