redux-react-session how to get user info into stat

2019-09-15 12:41发布

问题:

I new to react. I am trying to do login for that i used redux-react-session package from npm to store sessions.

I am able to store session and autherise routes based on login. But when i refresh page i want to restore user session into state.

As per document of redux-react-session we can user sessionService.loadUser() method to get user back.

This function return promise in response. But i am not able to get excat user object. Its returing user as a promise.

i have spend almost 10 hrs on it.

Can anyone help?

回答1:

It is hard to understand what is going wrong with your code. Can you share it somehow? Are you sure you call this line of code after store creation?

sessionService.initSessionService(store);

And finally you can implement such logic by yourself. After login, put data to the localStorage. After store creation, get data from the localStorage and put it in your store. It is pretty easy logic.