lin-cms-koa
lin-cms-koa copied to clipboard
请问该如何得到当前操作cms的用户id(即ctx.currentUser.id)?
我发现不能直接通过下面的方法来得到currentUser
bookApi.get('/user', async ctx => { const user = ctx.currentUser; if (!user) { throw new NotFound({ msg: '没有user' }); } ctx.json(user); });
这样是得不到ctx携带的currentUser信息的,请问有什么方法能直接在路由里获得ctx携带的currentUser
ctx.currentUser
指的是当前登录的用户,使用了 groupRequired
, loginRequired
, adminRequired
其一才会把当前登录用户挂载到 ctx.currentUser
上,具体的代码你可以看 app/middleware/jwt.js