I'm following thinkster tutorial for Angular2, and I made these two for checking if the user is authenticated:
private isAuthenticatedSubject = new ReplaySubject<boolean>(1);
public isAuthenticated = this.isAuthenticatedSubject.asObservable();
now, in my auth-gaurd.service.ts, I want to check the boolean value of isAuthenticated. How can I do that? I want to do something like this:
canActivate(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot
): Observable<boolean> {
//THIS IS NOT WORKING!
//Operator '===' cannot be applied to types 'Observable<boolean>' and 'boolean'
if (this.userService.isAuthenticated.take(1) === false) {
this.router.navigateByUrl('/login');
}
return this.userService.isAuthenticated.take(1);
}
You can find the complete code from thinkster here