cloudmu/react-redux-starter-kit

how to remove anonymous user and go to login page

Opened this issue · 3 comments

I don't know if this is the right place to ask this but when you start the app, It goes directly to the anonymous user, how to remove this behavior and go to the login page instead, thanks.

A quick fix would be to add the following in App.js

componentWillMount() {
    const { user } = this.props;
    const { router } = this.context;

    // If this page is restricted, go to loginPage first.
    // (But pass on this page's path in order to redirect back upon login)
    if (!user) {
      const path = this.props.location.pathname;
      router.push(`/login?redirect=${path}`);
    }
  }

But this may not be bullet-proof, but should get you going. I will check in a better solution when I have time.

It does the trick, thanks and keep up the good work!

Hello, with the new react router 4, this code to redirect no longer works, any hint on how to do this , thanks for your work.