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.
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.
Currently we track the current user by calling the backend API to get
req.user
, and store it into thecurrentUser
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, calllocalStorage.getItem()
to access the user in each component, and calllocalStorage.clear()
on logout.