I created a user state with redux toolkit everything works fine when the user is logged in the userActions sends a request to backend and returns the user info as token and username to display it on the navbar.the problem is the user state is returned to initial state after the page refresh.is it a good idea to use useEffect to send a request to backend after each rerender wich is not a good idea or to use the cash??
i tried to use RTK query to cash the user state but is it secure
2
Answers
That’s a normal behaviour, state is being reset on refresh per specification. If you want to preserve it you need to make use of localStorage/sessionStorage/cookies etc.
That’s where
cookies
come into play. You can save the user details incookies
for that session. It is good practice to maintain user details incookies
and data in thecookies
can be accessed by both client side and the server side.