mn22nw / favovid

0 stars 2 forks source link

dashboard inaccessible on reload #4

Closed mn22nw closed 8 years ago

mn22nw commented 8 years ago

If I reload the page when I am at the dashboard path (requires authentication) it redirects me to the start page even when I'm logged in...

This is (I think) due to the initial state for the user being ANONYMOUS and when reloading the app it takes a brief time for it to dispatch the LOGIN_USER action-type and set the auth.currently to LOGGED_IN instead of ANONYMOUS

At least long enough for it the home component to mount before the status is LOGGED_IN.

What I want to happen:

In home.js I've tried redirecting at componentDidMount() but as I wrote earlier the current auth status is Anonymous by then and therfore ignores the redirect.

componentDidMount() { 
    console.log('Auth currently = ', this.props.auth.currently )   
    if(this.props.auth.currently == C.LOGGED_IN) {
      this.props.redirectToDashBoard();
    }
  }

Same goes for the higher-ordered component authenticatedComponent.js where I also to make a redirect if the user is not logged in.

mn22nw commented 8 years ago

Since I was using redux-simple-router I found a solution by adding dispatch(updatePath('/dashboard')); after the user is authenticated in auth.js

That way, the user get's redirected to the dashboard if they reload the page