I'm trying to decode my token with jwt-decode but I can't. It gives me the following error. Does anyone know why?
ERROR Error: Uncaught (in promise): TypeError: jwt_decode_1.default is not a function TypeError: jwt_decode_1.default is not a function at RoleGuardService.canActivate (role-guard.service.ts?d7c4:19)
import jwt_decode from 'jwt-decode';
canActivate(route: ActivatedRouteSnapshot): boolean {
// this will be passed from the route config
// on the data property
const expectedRole = route.data.expectedRole;
const token = localStorage.getItem('token');
// decode the token to get its payload
const tokenPayload = jwt_decode(token);
console.log(tokenPayload);
if (
!this.auth.isAuthenticated() ||
tokenPayload.role !== expectedRole
) {
this.router.navigate(['login']);
return false;
}
return true;
}