Here is the code snippet I have been working on:
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
let isAuthenticated: boolean = false
this.authServiceLocal.isAuthenticated().then(response => isAuthenticated = response)
if(isAuthenticated){
return true
}
// If not logged in, redirect to login page with the return url
this.router.navigate(['/login'], { queryParams: { returnUrl: state.url }});
return false
}
I am trying to ensure that my code waits for the response from the service before checking the value of isAuthenticated. The server is providing the expected true and false values, so the issue seems to be related to the async nature of the call.