Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the recommended place to fetch user data using Redux when app starts?

Tags:

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.

like image 898
Vernon Avatar asked Jan 16 '17 17:01

Vernon


1 Answers

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.

like image 62
Vernon Avatar answered Sep 22 '22 10:09

Vernon