In general it's recommended not to store refresh tokens in local storage. The Auth0 documentation advises against it.

Even though I am aware of the underlying threats, what I am not aware is if there are any alternatives as to how to store those tokens in order to have persistence within the duration of a user's session when the API server is different than the client. If the tokens are only stored in memory, then the user will have to login every time he closes a tab for example and later on visits the site again.

Finally, I think anyway the refresh token rotation would mitigate the risk of having the tokens stolen. So in the lights of that, the above recommendation doesn't look very valid.

  • The refresh token is not supposed to survive user session. If the user logs out (i.e. the session is destroyed), the refresh token becomes invalid. Did you mean that refresh token should be persisted between browser/tab closures?
    – bhorkarg
    Mar 27, 2020 at 8:43
  • indeed, i've worded it better
    – tturbox
    May 9, 2020 at 13:57

1 Answer 1


Storing the refresh and access token is in JavaScript memory is generally considered much better than cookies or other browser storage.

You still don't need to worry about asking the user to login every time. The authorisation server (Auth0 in your case) maintains its own session (SSO Session) behind the scenes which is persistent. So it survives even if the user closes the browser.

This means that even if you have "lost" the refresh token stored in memory (e.g. if the user closes the tab), you just need to re-run the authorisation code flow to get new refresh and access tokens (i.e. redirect the user to the authorisation server). This should be silent to the user (i.e. they won't see the login screen) because of the same SSO session that is maintained by the authorisation server would still be active.

  • In oauth2.1-draft, it states that authorization servers shouldn't (ok, no must not) automatically process auth requests without user interaction. Maybe depending on the authorization server to automatically process those requests is not a futureproof solution?
    – tturbox
    May 7, 2020 at 21:40
  • 1
    How does the server identify the session of the browser if the tokens have been lost?
    – stoft
    Mar 31, 2021 at 7:27
  • 1
    Could you please explain why JavaScript memory is generally considered better than cookies or other browser storage for access tokens? If you have malicious JavaScript running (because of XSS), then can't that JavaScript read the memory anyway just as it can the local storage? Sep 17, 2021 at 0:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.