如何使用JSON Web令牌在有效负载中使用exp设置过期时间



我正在使用有效载荷将过期时间放入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);
}
jwt.sign({
data: 'foobar'
}, 'secret', {
expiresIn: 60 * 60 
});

60*60=1h设置秒数。

最新更新