Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialize currentUser state in redux store when necessary #17

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

kennethjiang
Copy link

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant