I'm encountering an error in IntelliJ when trying to use decodedJwt.scope
.
The error message is: Property 'scope' does not exist on type 'JwtPayload'. The only suggestions IntelliJ provides are: sub, aud, exp, iat, jti, iss, and nbf.
loadProfile(data: any) {
this.isAuthenticated = true;
this.accessToken = data['access-token'];
let decodedJwt = jwtDecode(this.accessToken);
this.username = decodedJwt.sub;
this.roles = decodedJwt.scope;
window.localStorage.setItem("jwt-token", this.accessToken);
}
I've used decodedJwt.scope
many times before without any issues, but now it suddenly doesn't seem to exist. Has anyone faced this issue before or knows how to resolve it?
I think that the latest version of the jwt-decode package doesn't have the scope property. I used version jwt-decode@^3.1.2, and it works.
<blink>
loadProfile(data: any) {
this.isAuthenticated=true;
this.accessToken = data['access-token'];
let decodedJwt: any = jwtDecode(this.accessToken);
this.username = decodedJwt.sub;
this.roles = decodedJwt.scope;
window.localStorage.setItem("jwt-token", this.accessToken);
}
</blink>