I have a service with this function that returns true or false on rather or not a token is valid
loggedIn() {
return this.http.get('http://localhost:3000/users/validateToken')
.map(res => res.json()).map(data => data.success);
}
I have a auth guard with can activate on protected routes that uses this.
canActivate(){
this.authService.loggedIn().subscribe(res => {
if(res) {
return true;
}
else {
this.router.navigate(['/login'])
return false;
}
})
}
But i get this error.
incorrectly implements interface 'CanActivate'. Types of property 'canActivate' are incompatible. Type '() => void' is not assignable to type '(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) => boolean | Promise | Obser...'. Type 'void' is not assignable to type 'boolean | Promise | Observable'.
How can i implement what I'm trying to do here ?