I am trying to implement this to use my authguard.
//authservice
constructor(private http: HttpClient, public jwtHelper: JwtHelperService) {}
public isAuthenticated(): boolean {
const token = localStorage.getItem('token');
console.log(token);
// controleer of er een token aanwezig is
if (!token) {
return false;
}
// controleer of de token is verlopen
return !this.jwtHelper.isTokenExpired(token);
}
}```
```ts
//my guard
@Injectable()
export class AuthGuard implements CanActivate {
constructor(private authService: AuthService, private router: Router) {}
canActivate(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot
): Observable<boolean> | Promise<boolean> | boolean {
if (!this.authService.isAuthenticated()) {
this.router.navigate(['loginpage']);
}
return true;
}
}
The error is only seen in the console. But i dont know how to handle this.
I do know it has something to do with jwthelperservice