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

umajs 做token验证时没有通用拦截方法吗? #73

Closed
chengxiaolong123 opened this issue Sep 24, 2021 · 4 comments
Closed

umajs 做token验证时没有通用拦截方法吗? #73

chengxiaolong123 opened this issue Sep 24, 2021 · 4 comments
Labels
question Further information is requested

Comments

@chengxiaolong123
Copy link

请求在进入controller之前,如果没有通过token验证,直接就返回前端,我看了源码,好像没找到。

@dazjean dazjean added the question Further information is requested label Sep 24, 2021
@dazjean
Copy link
Member

dazjean commented Sep 24, 2021

在controller路由被调用之前在umajs中可以通过插件进行拦截,这和koa中使用中间件一样,controller中被注册的路由始终是在中间件执行之后被调用,所以我们可以在插件中执行token校验这样的逻辑。具体使用可以参考官网插件和中间件章节内容;https://umajs.gitee.io/%E5%9F%BA%E7%A1%80%E5%8A%9F%E8%83%BD/Middleware.html

同时,umajs中可以使用AOP对某个路由方法的执行过程进行拦截,也是可以做到在method方法执行前后做一些校验和统一处理。

@dazjean
Copy link
Member

dazjean commented Sep 24, 2021

https://github.com/Umajs/plugin-csrf 这儿有csrf拦截的插件实现,可参考。

@chengxiaolong123
Copy link
Author

chengxiaolong123 commented Sep 24, 2021 via email

@dazjean
Copy link
Member

dazjean commented Sep 24, 2021

嗯嗯,已经解决了,对aop不熟,看java的代码才知道需要用around的方法。谢谢指引。这个框架不错,希望能有更多人使用。

------------------ 原始邮件 ------------------
发件人: @.>;
发送时间: 2021年9月24日(星期五) 晚上9:25
收件人: @.
>;
抄送: @.>; @.>;
主题: Re: [Umajs/Umajs] umajs 做token验证时没有通用拦截方法吗? (#73)

在controller路由被调用之前在umajs中可以通过插件进行拦截,这和koa中使用中间件一样,controller中被注册的路由始终是在中间件执行之后被调用,所以我们可以在插件中执行token校验这样的逻辑。具体使用可以参考官网插件和中间件章节内容;https://umajs.gitee.io/%E5%9F%BA%E7%A1%80%E5%8A%9F%E8%83%BD/Middleware.html

同时,umajs中可以使用AOP对某个路由方法的执行过程进行拦截,也是可以做到在method方法执行前后做一些校验和统一处理。


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.

感谢支持,希望可以给身边人推荐一下帮增加些关注,对aop使用这块我们建议只使用around方法,在即将发布的2.0版本框架会剔除before和after。最新动向可以加微信Da_ZJean进群沟通交流。

@dazjean dazjean closed this as completed Oct 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants