react-devise
react-devise copied to clipboard
Initialize `currentUser` state in redux store when necessary
There is a problem in current behavior:
- at the moment of user logging in,
currentUserstate is established in redux store. Authtoken is saved to local storage. Then it is load the component protected by<PrivateRoute>.<PrivateRoute>checks thatcurrentUseris present in state and hasisLoggedIn. So everything works. - However, when the page is refreshed, there is no code to re-establish
currentUserstate in redux store (unlessredux-persistis used), even though the token is still in local storage. When<PrivateRoute>tries to checkcurrentUser, it can't find it. So it rejects the route.
This PR is to initialize currentUser state in redux store from local storage upon page reload.
This PR is to address #16
Oh, I ran into errors when running yarn test. So I didn't test it. But the similar code works on my current project.