Search code examples
javascriptreactjsauthenticationjwttoken

how to save user token after every request


I have a problem relate to saving token, I have asked some developers and they told me that I shouldn't save my token in localStorage or in Browser
I'm building a react app, so every time the user goes from page to another page I have to reload user information using that token.
My question how to save that token so I can call that token every time I need it?


Solution

  • Avoid using Local Storage because it's available to other 3rd party scripts and is susceptible to XSS attacks.

    Instead, store it in an httpOnly cookie where it will be safe from potentially harmful JavaScript scripts.

    https://blog.logrocket.com/jwt-authentication-best-practices/
    https://dev.to/rdegges/please-stop-using-local-storage-1i04