koa-jwt 如何设置过期时间
发布于 8 年前 作者 Qquanwei 13450 次浏览 来自 问答

rt所示 , 超过12小时token失效

6 回复

@jingsam 我用的koa-jwt 目前想直接在secret加个时间值,不知道koa-jwt可以直接设置不

为什么不仔细看下文档呢?

You can specify audience and/or issuer as well:

app.use(jwt({ secret:   'shared-secret',
              audience: 'http://myapi/protected',
              issuer:   'http://issuer' }));

If the JWT has an expiration (exp), it will be checked.

后面找到了,在这里记录一下

const jwt = require("jsonwebtoken");
let userToken = {  id: '123', name: "lmx" };
//	12h 表示 12小时
jwt.sign(userToken,  "secret", { expiresIn: "12h" })

//	也可以这样 60 seconds * 60 minutes * 12 = 12 hour
jwt.sign(userToken, "secret", { expiresIn: 60 * 60 * 12 });

回到顶部