Is it possible to retreive one information from a localStorage key ?
I have a key containing for example various information about the user after a connection :
{"id":1,"email":"AnEmail@Gmail.com","roles":SimpleUser,"iat":SomeNumber,"exp":SomeNumber}
And one of my axios request is : passing the user id in the URL, like this :
export const getAllOfSomething = (userId) => axios.get(`${URL}/something/${userId}`,
{
userId: userId,
});
Probably a stupid question but I'm still learning everything
EDIT : I store my key like this when a connection is good :
const handleSubmit = event => {
event.preventDefault();
login(event.target.email.value, event.target.password.value).then(response => {
const Token = response.data.accessToken;
localStorage.setItem('UserToken', Token);
User = jwt_decode(Token)
localStorage.setItem('User', JSON.stringify(User))
history.push({
pathname: '/',
});
window.location.reload(false);
}).catch(err => {
setErrorForm(err.response.data.message);
});
};
The first localStorage.setitem is to only store the JWT Token.
The seconde one, I decode this Token to retrieve all the information about the user and this is what i get in my localStorage after decode :
