amplify-js: TypeError: user.sendMFACode is not a function

aws-amplify, v0.1.36 (non-React version).

While calling confirmSignIn:

        Auth.confirmSignIn(this.user, this.confirmationCode)
            .then(data => this.handleResponse(data))
            .catch(err => this.handleError(err));

I’m getting the following error: TypeError: user.sendMFACode is not a function

I checked the user object and it doesn’t have this function, so not sure where the disconnect is. The actual registration is successful. Here’s the code that fails: https://github.com/aws/aws-amplify/blob/fc8722ee79f5a691843901af3729be57dbadba0b/packages/aws-amplify/src/Auth/Auth.ts#L247

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 15 (2 by maintainers)

Most upvoted comments

Getting the same error with react-native. aws-amplify version 0.2.14 TypeError: user.sendMFACode is not a function

Somehow the CognitoUser object received in response of Auth.signIn(username,password) doesn’t have this sendMFA function. It does contain challengeName : "SMS_MFA"

I am experiencing the same issue in Angular

Hey @vbudilov just wanted to confirm. The user object in your call to Auth.confirmSignIn, was it from signIn method response? Also, need to make sure the challengeName was ‘SMS_MFA’.

Something like this:

Auth.signIn(username, password)
  .then(user => {
    if (user.challengeName === 'SMS_MFA') {
      // somehow get the code, then
      Auth.confirmSignIn(user, code)
        .then(() => /* success */ )
        .catch(() => /* error */ )
    }
  });

Or keep user object to be used later:

signIn(username, password) {
  const that = this;
  Auth.signIn(username, password)
    .then(user => {
      if (user.challengeName === 'SMS_MFA') {
        that.user = user;
      }
    });
}

confirm(code) {
    Auth.confirmSignIn(this.user, code)
      .then(() => /* success */ )
      .catch(() => /* error */ )
}

Thanks, @asalia-marine. I’m using redux-saga as well. I have the Auth.confirmSignUp working, just getting hung up with Auth.confirmSignIn as the user object from Auth.signIn does not return the user.sendMFACode function as the issue suggests. Do you know the difference between redux-saga and redux-thunk in relation to how the Amplify endpoints might return objects? I’m curious too if there is a way to write the sendMFACode function into the code itself if the object is not going to return it.