I'm currently building a dashboard using Redux and React. I'm also implementing react-router and redux-router to redirect users when they're not logged in.
I'm not exactly sure what the recommended place is to fetch user data once the app starts. I would only like to fetch the user if a cookie is present (we're not going to use SSR).
What would be the best moment to check for the presence of the cookie and fetch the user data (and update the app's state)?
Because some routes shouldn't be available for non-authenticated users, I believe authentication should be checked in the router. However, I'm not sure what would be the best place to do this (maybe onEnter
)?
Help would be appreciated!
Thanks.
I believe this Stack Overflow answer is what I was looking for: Where do I fetch initial data from server in a React Redux app?
There's indeed no need for components to be involved while I'm just fetching initial state.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With