我正在使用有效负载将到期时间放入JWT中。我很困惑时间如何工作。在这里,我看到了一个示例,该示例将到期时间设置为一天。如何设置以秒,分钟或小时为单位的时间?
resetToken = user => {
return JWT.sign({
iss: 'xyz',
sub: user._id,
iat: new Date().getTime(), // current time
exp: new Date().setDate(new Date().getDate() + 1) // current time + 1 day ahead
}, Keys.JWT_RESET);
}
答案 0 :(得分:0)
jwt.sign({
data: 'foobar'
}, 'secret', {
expiresIn: 60 * 60
});
60 * 60 = 1小时 设置秒数。