๐—ฆ๐˜๐—ผ๐—ฝ ๐—จ๐˜€๐—ถ๐—ป๐—ด ๐—Ÿ๐—ผ๐—ฐ๐—ฎ๐—น๐—ฆ๐˜๐—ผ๐—ฟ๐—ฎ๐—ด๐—ฒ ๐—ณ๐—ผ๐—ฟ ๐—”๐˜‚๐˜๐—ต ๐—ง๐—ผ๐—ธ๐—ฒ๐—ป๐˜€

You have five ways to store data in a browser. Most developers pick the wrong one.

Ask yourself three questions. How big is the data? Who needs to read it? How long should it stay?

Here are your options.

Many tutorials tell you to put auth tokens in localStorage. This is a mistake.

Any script on your page reads localStorage. A single security hole lets a hacker steal your token. They steal the user session.

Use HttpOnly cookies instead. JavaScript is unable to read these. The browser sends them to the server. Your users stay safe.

Pick based on these rules.

Most apps only need three. Use an HttpOnly cookie, localStorage, and sessionStorage.

Source: https://dev.to/dip_032d2fe1959e1990ddbb1/should-we-use-localstorage-for-storing-auth-token-5g51