Это в userService
public isAuthenticated(): Observable<boolean> {
return this.getUser().pipe(
map(data => !!data['login'])
);
}
это в authGuard
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) : Observable<boolean>{
return this.userService.isAuthenticated().pipe(
tap((isAuthenticated: boolean) => {
if (!isAuthenticated) {
this.router.navigate(['/login'])
}
})
);
}