基于koa2的koa-jwt和基于koa1有很大差别,前者去掉了对sign,verify和decode函数的支持。我想问一下,我现在把jwt引入了:const jwt = require('koa-jwt');app.use(jwt({ secret: 'my-secret' }).unless({path: [/^\/backend\/login/]}));但是因为没有sign函数,我在/login接口返回的时候应该怎样把token加到返回的body中?
1 回答
跃然一笑
TA贡献1826条经验 获得超6个赞
因为之前没用过,文档写得也不是很细致,看得不是很明白。大概这里有一句话,是说默认用 ctx.state.user,所以你试下呢
The JWT authentication middleware authenticates callers using a JWT token. If the token is valid,
ctx.state.user(by default) will be set with the JSON object decoded to be used by later middleware for authorization and access control.
添加回答
举报
0/150
提交
取消
