Unhandled Rejection (TypeError): user.getSession is not a function

Viewed 932

I am using AWS amplify in my app, I implemented a login function with google. But after login, i get this error Unhandled Rejection (TypeError): user.getSession is not a function .

I have used Auth.federatedSignIn function for the login.

Here is my code:

       const responseGoogle = async (response) => {
    try {
      setLoading(true);
      const user = {
        name: response.profileObj.name,
        email: response.profileObj.email
      };

      const password = await Auth.forgotPassword(user.email);

      let expires_at = addMilliseconds(new Date(), 3600 * 1000).getTime();

      const result = await Auth.federatedSignIn(
        'google',
        { token: response.tokenId, expires_at },
        user
      );

      console.log(result);
      console.log('heree');

      history.push('/classes/google');
      setLoading(false);
      setUserInfo(loadedUsers, email);
    } catch (error) {
      console.log(error);
      if (error.message !== `Cannot read property 'name' of undefined`) {
        enqueueSnackbar(error.message, { variant: 'error' });
      }
      setLoading(false);
    }
  };

The response is the response that I get from google.

does anyone know why I am getting this error? appreciated any type of help. Thanks

1 Answers

Firstly you have to check all restrictions auth is at the config json when you create auth function

The second thing is you have to pass three parameters in order to change passwords such as

  • User Is the user session and you can get it by fetch the current sesion token and auth data.
  • Oldpassword
  • New Password
Related