lin-cms-koa icon indicating copy to clipboard operation
lin-cms-koa copied to clipboard

请问该如何得到当前操作cms的用户id(即ctx.currentUser.id)?

Open tclcm1987 opened this issue 4 years ago • 1 comments

我发现不能直接通过下面的方法来得到currentUser bookApi.get('/user', async ctx => { const user = ctx.currentUser; if (!user) { throw new NotFound({ msg: '没有user' }); } ctx.json(user); }); 这样是得不到ctx携带的currentUser信息的,请问有什么方法能直接在路由里获得ctx携带的currentUser

tclcm1987 avatar Jun 22 '20 10:06 tclcm1987

ctx.currentUser 指的是当前登录的用户,使用了 groupRequired, loginRequired, adminRequired 其一才会把当前登录用户挂载到 ctx.currentUser上,具体的代码你可以看 app/middleware/jwt.js

smileShirmy avatar Jun 23 '20 00:06 smileShirmy