0

I have created user authentication with passport local strategy and i use session. Everytime the user logged in session is stored in database and the browser. In my frontend can use the user.id to store it in local storage as a key or token ?

  • if this answered your question, please mark as solved :) – KLTR Dec 20 '18 at 08:56
  • I understand the difference. My question is approciate to store the user.id as the token or key for the localStorage on my react App – Sadiq Mustapha Aji Dec 20 '18 at 09:11
  • you can use both, it depends on how you want to make it. your decision should come from the understanding of the differences between the 2. – KLTR Dec 20 '18 at 09:24
  • 1
    Possible duplicate of [HTML5 Local storage vs. Session storage](https://stackoverflow.com/questions/5523140/html5-local-storage-vs-session-storage) – Peter Dec 20 '18 at 09:55

1 Answers1

4

LocalStorage

Stores data with no expiration date, and gets cleared only through JavaScript, or clearing the Browser cache / Locally Stored Data Storage limit is the maximum amongst the three (including cookies)

SessionStorage

The sessionStorage object stores data only for a session, meaning that the data is stored until the browser (or tab) is closed. Data is never transferred to the server. Storage limit is larger than a cookie (at least 5MB).

KLTR
  • 1,263
  • 2
  • 14
  • 37