How do I handle authentication state in a SPA react app?
Hello,
I have implemented authentication in my backend that uses http only cookies, so now I am not sure how do I handle authentication state in a SPA react app.
When the user logs in I would like to store the auth state in a store like React Context or Zustand, but what if the user closes the app and opens it again? Should I hit an API route like
getUser
every time he opens it and if it returns the user that means he is sill logged in?
Should I use Provider component (React Context) that wraps the whole app that checks the API?
I would like to use a HashRouter
instead of a BrowserRouter
in my app.
Thanks.2 Replies
Solution
Unknown User•2mo ago
Message Not Public
Sign In & Join Server To View
Thank you very much