I need to verify the source code for authentication, however the te code exits before verification is complete. Which will lead to uncontrollable.
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
this.isAuthenticated();
return this.authenticated;
}
isAuthenticated(){
this.loginService.isAuthenticated()
.subscribe(status => this.authenticated = status)
}
How can I change this code, so I wait until the observable completes to get an authenticated status before the code returns.
Note. The canActivate Angular method prevents me from writing code, as shown below:
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
this.loginService.isAuthenticated()
.subscribe(status => {
this.authenticated = status;
return this.authenticated;
});
}
This results in the following error:
'AuthGuard' 'CanActivate'.
'canActivate' . Type '(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) = > void' '(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) = > boolean | | Pr... '. 'void' 'boolean' | Promise".
.