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
Should I use Provider component (React Context) that wraps the whole app that checks the API?
I would like to use a
Thanks.
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.
