我如何使用 fastify-jwt 来签署带有过期时间的令牌?

How can I use fastify-jwt to sign a token with expiredtime?

如果我们不需要expiredIn,就用这种方式,我可以创建一个token

const token = await reply.jwtSign(userJSON)

但我想给个时间,令牌应该disabled:expiredIn! 给个expiredTime怎么办

根据 documentation

expiresIn: expressed in seconds or a string describing a time span zeit/ms. Eg: 60, "2 days", "10h", "7d". A numeric value is interpreted as a seconds count. If you use a string be sure you provide the time units (days, hours, etc), otherwise milliseconds unit is used by default ("120" is equal to "120ms").

您必须在调用 jwtSign 时使用 expiresIn 选项,例如:

const token = await reply.jwtSign(userJSON, { expiresIn: '1h' })

对于 1 小时后过期的令牌。