I have an angular2 c protector canActivate()that calls a service for isLoggedIn()and returns a promise, which is then resolved, and the route is handled accordingly.
However, I am trying to do the opposite, see when the user is not logged in and it does not work.
I tried something just as simple (adding an operator!), Hoping this would work:
@Injectable()
export class AuthGuard implements CanActivate {
constructor(private authService: AuthService) {}
canActivate() {
return !this.authService.isLoggedIn();
}
}
However, this always returns false, and the route is never activated.
This is a relevant excerpt from my function isLoggedIn():
isLoggedIn(): Promise<Boolean> {
var component = this;
return new Promise((resolve, reject) => {
component.queryForUser((user) => {
resolve(user != null);
});
}
});
}
If the user is not equal null, then he is logged in and the promise is resolved using true. Otherwise, a lie.
, , , isNotLoggedIn(), , , : canActivate()?