NodeJS 在nestjs中解码JWT令牌时nbf时间错误

jjjwad0x  于 11个月前  发布在  Node.js
关注(0)|答案(1)|浏览(121)

在我的app.module中,我将JWT注册为:

JwtModule.register({
      secret: `${process.env.JWT_SECRET}`,
      signOptions: {
      expiresIn: "24h" ,
      notBefore:  Math.floor(new Date().getTime() / 1000) ,
      
    },

字符串
但当我解码令牌时,我得到这些时间戳:

iat: 1699944419,
 nbf: 3399888838,
 exp: 1700030819


nbf times显示错误的日期时间(2077年9月26日星期日下午5:03:58)

5jdjgkvh

5jdjgkvh1#

jsonwebtoken的notBefore字段似乎是相对于当前时间的时间。如果您传递一个数值,(你这样做了),该值将被视为秒,这就是为什么你在此刻加倍时间。You can see herenbf被分配the current timestamp plus the notBefore option,这导致了加倍的时间。给予一个相对于电流的时间,而不是绝对时间。

相关问题