Save API token to local storage ReactJS

As per to auth0 "Don't store tokens in local storage" as "Browser local storage (or session storage) is not a secure place to store sensitive information"

They rather using cookies please refer to : https://auth0.com/docs/tokens/guides/store-tokens#don-t-store-tokens-in-local-storage


localStorage is a global variable. You can use it in your react code just like

localStorage.setItem('itemName', value)
localStorage.getItem('itemName')

You shouldn't use localStorage because it is NOT safe and is accessible through JavaScript .


You most use the following code:

To set a value:

localStorage.setItem('myData', data);

To get a value:

localStorage.getItem('myData');

Tags:

Reactjs