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

Created on 26 Jan 2018  路  12Comments  路  Source: aws-amplify/amplify-js

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

investigating

Most helpful comment

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"

All 12 comments

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 */ )
}

Please feel free to reopen this issue in case you still have problems with this.

Thanks!

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"

@asalia-marine Were you able to move past this issue? Experiencing the same response even with challengeName : "SMS_MFA" when using Auth.confirmSignIn. Any suggestions? Here is a screenshot of the response object: https://d.pr/i/AX6IQI /cc @elorzafe @vbudilov @richardzcode

@grgaortiz I was using redux-saga, and the amplify API calls were written in the generator functions. I was not able to get this to work with that setup, Had since shifted to redux-thunk and got the api calls working.

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.

I am experiencing the same issue in Angular

@elorzafe @richardzcode - Should we open a new issue or is there a way to re-open this specific one? Either way, any thought on the details above?

I am having this same issue. I am passing the user object returned by Auth.signIn() as the first parameter in Auth.confirmSignIn(user, "123456", "SMS_MFA"). but yet that user object still does not have the sendMFACode function.

Error: TypeError: user.sendMFACode is not a function

Anyone still having issues with this?
"@aws-amplify/auth": "^1.2.25",

I'm having an issue with this. I am autoconfirming my user on sign up and immediately logging them in, with auto verification and MFA enabled. I save the user returned from the sign up in localstorage in case of page refresh and then retrieving it and passing it, along with the user provided code, to auth.confirmSignIn. Anyone find a solution for this one?

my issue turned out to be that saving the session user in local storage does not work unless you stringify the json and unstringify it when you fetch it (I think). I kept seeing [Object object] stored as the value in application storage when I tried to cache the session User.

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"

Same issue here. Have. you resolved it ?

Was this page helpful?
0 / 5 - 0 ratings