bernabe9 / redux-react-session

:key: Simple Session API storage for Redux and React
https://bernabe9.github.io/redux-react-session/
147 stars 41 forks source link

able to login and redirecting to home page but going back to login page on refresh #20

Closed Gowtham-2016 closed 6 years ago

Gowtham-2016 commented 6 years ago

Where are we assigning the authenticated props as true i don't see anywhere in the code where we are setting its value as true, i know that the default value is false

bernabe9 commented 6 years ago

After you logged in (using saveSession) the flagauthenticated will change from false to true, and will be saved in the Redux store within session.authenticated.

Your Redux Store should look like this after log in:

store =  {
  session: {
    authenticated: true,
    checked: true,
    user: { other user props... }
  },
  other props in the store...
}
freddyamsterdam commented 6 years ago

@bernabe9

I'm not entirely sure if this is what @Gowtham-2016 means, but when refreshing the browser, the session is a bit late to the party:

screen shot 2018-03-07 at 17 32 16

In my case, my router is rendered conditionally, depending on what the session state is. It seems like the router is actually beating the session to the finish line and performing any route matching before the sessionService is initialised.

Any ideas?

freddyamsterdam commented 6 years ago

@Gowtham-2016 #27 might provide the solution to your problem - although I can't quite tell as your issue is a bit too vague to know for sure.

bernabe9 commented 6 years ago

@freddyamsterdam as you said, the session is checked asynchronously, so the app needs to wait for the session to launch the app. I commented on this issue how to do that #27

freddyamsterdam commented 6 years ago

Cheers @bernabe9!