So, getSuppliers() returns null despite the existence of: token.
class Supplier {
constructor() {
this.getSuppliers();
}
getToken() {
const jwtTokenString = localStorage.getItem('status.authorisation.token');
const jwtToken = jwtTokenString ? JSON.parse(jwtTokenString) : null;
return jwtToken;
}
getSuppliers() {
console.log(this.getToken());
}
}
What I'm trying:
getToken() {
const jwtTokenString = localStorage.getItem('authorisation.token');
const jwtToken = jwtTokenString ? JSON.parse(jwtTokenString) : null;
return jwtToken;
}
getToken() {
const jwtTokenString = localStorage.getItem('authorisation.token');
const jwtToken = jwtTokenString ? jwtTokenString : null;
return jwtToken;
}
getToken() {
const jwtTokenString = localStorage.getItem('token');
const jwtToken = jwtTokenString ? jwtTokenString : null;
return jwtToken;
}
What's the correct way to retrieve the token?

You can't access the localstorage like an object
localStorage.getItem('authorisation.token');you should call.getItem('the name like you set it')and then when youparseit then you can access it like an object.If you want to access it like an object for example you can do this.