简体   繁体   English

canActivate - 减慢应用程序的速度。 什么时候调用它?

[英]canActivate - slows down the app. When to call it?

I have an angular app with .net core back-end.我有一个带有 .net 核心后端的 angular 应用程序。 I am using windows active directory for user authorization/identification.我正在使用 windows 活动目录进行用户授权/识别。 Everything is working, but I have a feeling that the app is slow... I have confirmed that this is happening because because I am checking is user valid on each component load.一切正常,但我感觉应用程序很慢......我已经确认这种情况正在发生,因为我正在检查每个组件加载时用户是否有效。

canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean | UrlTree> {
    if (this.auth.isAuthenticated) {
       return true;
    } else {
       return this.router.parseUrl('/notAuthorized');
    }
});

"isAuthenticated" is a method which is calling a back-end and checking is user valid or not. “isAuthenticated”是一种调用后端并检查用户是否有效的方法。

So, any suggestion about a best practice for handling this kind of situation?那么,关于处理这种情况的最佳实践有什么建议吗?

Because of server call on each route, it is slowing down, you can store your AuthSession in session storage and check whether Session is present or not由于每个路由上的服务器调用,它都变慢了,您可以将您的 AuthSession 存储在 session 存储中并检查 Session 是否存在

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM