【发布时间】:2017-02-08 01:20:42
【问题描述】:
payload的exp字段应该如何表达?
jwt.sign({
_id: this._id,
email: this.email,
name: this.name,
exp: //how do I set this value ?,
}, "MY_SECRET");
文档中没有明确解释
https://github.com/auth0/node-jsonwebtoken
从我这里的示例代码:
userSchema.methods.generateJwt = function() {
var expiry = new Date();
expiry.setDate(expiry.getDate() + 7);
return jwt.sign({
_id: this._id,
email: this.email,
name: this.name,
exp: parseInt(expiry.getTime() / 1000),
}, "MY_SECRET");
};
我假设“exp”表示令牌的到期日期,以从纪元开始的秒数为单位。 对吗?
【问题讨论】:
-
是的,
expiry将在几秒钟内完成
标签: node.js express json-web-token