react-devise icon indicating copy to clipboard operation
react-devise copied to clipboard

Initialize `currentUser` state in redux store when necessary

Open kennethjiang opened this issue 6 years ago • 1 comments

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 that currentUser is present in state and has isLoggedIn. So everything works.
  • However, when the page is refreshed, there is no code to re-establish currentUser state in redux store (unless redux-persist is used), even though the token is still in local storage. When <PrivateRoute> tries to check currentUser, 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

kennethjiang avatar Oct 10 '18 17:10 kennethjiang

Oh, I ran into errors when running yarn test. So I didn't test it. But the similar code works on my current project.

kennethjiang avatar Oct 10 '18 17:10 kennethjiang