I have auth guard service
constructor(private _auth: AuthService, private _router: Router) { }
canActivate() {
if(this._auth.isLoggedIn()){
return true;
} else {
this._router.navigate(['/login']);
return false;
}
}
and that's my isloggedin method
isLoggedIn(): boolean {
return this._session.sessionId.length > 0;
}
and login
login(user: User): any {
return this._http.post(this.authUrl, user)
.subscribe(x => {
this._session.sessionId = x.sessionId;
this._session.name = x.username;
});
}
my problem is that after login it first check's isloggedin
and I think it's because of subscribe
(login method waits response from server)
so I added asObservable.first()
in isLoggedIn
isLoggedIn(): boolean {
return (this._session.sessionId.length > 0).asObservable().first();
}
but it logs in console that
Property 'asObservable' does not exist on type 'boolean'.
How can I solve that?