ruichen199801 / forxnews

CIS550 database course project
https://youtu.be/nuDBwg3mG6o
0 stars 1 forks source link

[Improvement] Persist Logged-in User in LocalStorage #25

Closed ruichen199801 closed 1 year ago

ruichen199801 commented 1 year ago

Currently we track the current user by calling the backend API to get req.user, and store it into the currentUser state in the local component. We want to avoid repeated backend API calls every time the component is rendered.

Therefore, we should store the user in the global LocalStorage instead. We will call localStorage.setItem() to store user on login success, call localStorage.getItem() to access the user in each component, and call localStorage.clear() on logout.

ruichen199801 commented 1 year ago

Storing current user in LocalStorage only works for local username password login. It doesn't work for third-party auth. So we'll stick to the current implementation of getting user from req.user.