Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tclcm1987 opened this issue Jun 22, 2020 · 1 comment
Labels

Comments

@tclcm1987
Copy link

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

@smileShirmy
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants