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,
currentUser
state is established in redux store. Authtoken is saved to local storage. Then it is load the component protected by<PrivateRoute>
.<PrivateRoute>
checks thatcurrentUser
is present in state and hasisLoggedIn
. So everything works. - However, when the page is refreshed, there is no code to re-establish
currentUser
state in redux store (unlessredux-persist
is 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.