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

中间件怎么给后面的controller传值? #742

Closed
callmesoul opened this issue Apr 11, 2017 · 5 comments
Closed

中间件怎么给后面的controller传值? #742

callmesoul opened this issue Apr 11, 2017 · 5 comments

Comments

@callmesoul
Copy link

我想问下,我用jwt验证,在中间间的时候解析了token,然后怎么把解析后的信息传给后面的controller用的呢?我试过this.request.api_user=user或者this.locals.api_user=user都不行啊,求教

@atian25
Copy link
Member

atian25 commented Apr 12, 2017

直接赋值给 this.user 就好了.

可以参考下

@callmesoul
Copy link
Author

@atian25 thx

@bshy522
Copy link

bshy522 commented Apr 12, 2017

这种最好放在 state 里面吧。 我记得 koa 也是这么推荐的。

ctx.state.token = '';

https://github.com/koajs/koa/blob/f191c0def4859cb7f89a13dad96bc23040daf959/docs/api/context.md#ctxstate

@atian25
Copy link
Member

atian25 commented Apr 12, 2017 via email

@atian25
Copy link
Member

atian25 commented Apr 12, 2017 via email

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

No branches or pull requests

4 participants