0

I have an angular app with .net core back-end. I am using windows active directory for user authorization/identification. 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.

So, any suggestion about a best practice for handling this kind of situation?

sosNiLa
  • 289
  • 6
  • 18
  • 3
    `"isAuthenticated" is a method which is calling a back-end and checking is user valid or not` this is the problem here . if you are using token based authendication just store the token in the local sorage and check if token is available or not. no need to check with backend for each time canActivate is called. all you have to do is to create a error interceptor for `401` and logout accordingly. Please check the article : https://jasonwatmore.com/post/2019/06/10/angular-8-user-registration-and-login-example-tutorial – Joel Joseph Nov 20 '19 at 12:40

1 Answers1

2

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

Mustafa Kunwa
  • 821
  • 1
  • 9
  • 19
  • thanks but I am using windows active directory, so I am not really sure how to use AuthSession... – sosNiLa Nov 22 '19 at 12:42