skip to Main Content

I have already get the access Token and user information using the API end point but now I want to login into please help me how I can login into and get currentAuthenticatedUser, I have not login with user and pass word because I have using Facebook/Google Web UI login into aws.

Hub.listen("auth", ({ payload: { event, data } }) => {
  switch (event) {
    case "signIn":
      Auth.currentAuthenticatedUser().then(user => {
        this.setState({ user, error: null, loading: false });
        debugger
      });
      break;
    case "signOut":
      this.setState({ user: null, error: null, loading: false });
       debugger
      break;
  }
});

2

Answers


  1. Could you try this?

        Hub.listen("auth", async ({ payload: { event, data } }) => {
          switch (event) {
            case "signIn": {
              this.setState({ user: data,error: null, loading: false });
              break;
            }
            case "signOut": {
              this.setState({ user: null, error: null, loading: false });
              break;
            }
          }
        });
    
    
    Login or Signup to reply.
  2. Please try below code, it may be work for you:

    `

    componentDidMount() {
        Hub.listen('auth', this);
    }
    
    onHubCapsule(capsule) {
      debugger
        const { channel, payload, source } = capsule;
        if (channel === 'auth' && payload.event === 'signIn') { 
          this.checkUser();
       }else{
        this.setState({user :  null});
       }
    }
    
    checkUser() {
         Auth.currentAuthenticatedUser().then((user) => {
          this.setState(user)
         });
    }
    

    `

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search