Correct setup for user-store with zustand react-query and axios

I'm starting a new react project and i trying to use all these library together:
  • zustand
  • react-query
  • axios
  • react router
I want to configured axios to redirect the user to the login page when the apis respond with a 401,

Then i want to create a userStore which loads the user info from local storage so i'm using zustand persist middleware

Now when the react app starts i want to call /api/auth/me to verify that the user is still logged in and that the information in the userStore are up to date.
For this i want to use use react query to make an api using the axiosInterceptor instance declered above and i cannot find where i can do that.

I will also need to retrive a csrf token and set it in the header inside axios but i haven't worked on it yet

I'm i doing this correctly?

you can find the relevant code in the attachments
Was this page helpful?