Answer the question
In order to leave comments, you need to log in
How to implement this Guard correctly?
Help implement this guard. The problem is that always false is returned. (getUser makes a request to the test api and gets the object).
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
return this.auth.getUser().subscribe( u => {
this.person = u;
if (this.person.err == 0 ) {
return true;
} else {
return false;
}
});
}
Answer the question
In order to leave comments, you need to log in
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
return this.auth.getUser().pipe( map(user => user.err == 0));
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question