'How to access tokens stored in local storage?

Suppose a user logs into my web app and my web app produces a access token and stores it in local storage in client side. But when user enters into other webpage in the same domain, How can I get the access token in local storage along with the request so that the server knows that user is already authenticated?



Solution 1:[1]

To set localStorage data from response:

localStorage.setItem('access_token', response.data.token);

To get localStorage data:

let authorizationToken = localStorage.getItem("access_token");

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Alex Tom