AnomalyInnovations / serverless-stack-demo-client

Source for the demo app client in the Serverless Stack Guide
https://demo2.serverless-stack.com
MIT License
635 stars 204 forks source link

Is AuthenticatedRoute.js really needed? #45

Closed pig800509 closed 6 years ago

pig800509 commented 6 years ago

Through app.js

async componentDidMount() {
    try {
      if (await Auth.currentSession()) {
        this.userHasAuthenticated(true);
      }
    }
    catch(e) {
      if (e !== 'No current user') {
        alert(e);
      }
      this.props.history.push("/");   // Simply add this line to protect all path
    }
    this.setState({ isAuthenticating: false });
  }

Why do you want to use AuthenticatedRoute.js ?

jayair commented 6 years ago

@pig800509 The AuthenticatedRoute.js and the UnauthenticatedRoute.js are necessary to handle the login and logout when you don't load the app for the first time. So imagine you hit the logout and you need to redirect after the button is clicked. You can handle this by adding redirects in different spots. The two components just simplify the process so that the redirects are done is the same spot.

We talk about it here - https://serverless-stack.com/chapters/setup-secure-pages.html.

pig800509 commented 6 years ago

OK thanks