I created the following AuthenticatedGuard in Angular 9:
export class AuthenticatedGuard implements CanActivate {
constructor(private authenticationService: AuthenticationService) { }
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | Promise<boolean> | boolean {
return this.authenticationService.isSignedIn();
this.authenticationService.signInRedirect({ state: { url: state.url }}).subscribe();
}
}
The method authenticationService.isSignedIn
returns an Observable<boolean>
and authenticationService.signInRedirect()
returns an Observable<any>
.
The behaviour should be:
If authenticationService.isSignedIn
is false
then do:
this.authenticationService.signInRedirect({ state: { url: state.url }}).subscribe();
Can this be done and still use Observable?