如何使用有效载荷中的exp和JSON Web令牌设置到期时间

时间:2020-08-16 15:31:29

标签: node.js time jwt

我正在使用有效负载将到期时间放入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);
}

1 个答案:

答案 0 :(得分:0)

jwt.sign({
   data: 'foobar'
 }, 'secret', {
   expiresIn: 60 * 60 
});

60 * 60 = 1小时 设置秒数。