So basically when I login my backend returns me a token so I store it like:
// var token is global
token = res.data.token;
sessionStorage.setItem("token", token);
And when I logout I just remove the items from sessionStorage and reset the var:
token = '';
sessionStorage.removeItem("token");
Then in all my requests I use the var to create the header
{ headers: { "Authorization": "Bearer " + token } }
But I don't know if i should keep the token var or just access the storage for each request like:
{ headers: { "Authorization": "Bearer " + sessionStorage.getItem("token"} }
Right now I just use the storage in case the user refresh the page, so he doesn't lose javascript context, because I thought is more efficient than accessing the storage for each request, but I don't know what is the best approach security-wise, or what do usually developers do?