When executing the following code:
export const sendMFACode = ( mfaCode ) => {
// Create userPool
let userPool = new CognitoUserPool( poolData );
//Get logged in user
let cognitoUser = userPool.getCurrentUser();
// sendMFACode
cognitoUser.sendMFACode( mfaCode, {
onSuccess: function( result ) {
// User authentication was successful
console.log( 'result', result );
},
onFailure: function( err ) {
// User authentication was not successful
console.log( 'err', err );
},
} );
};
I get the following error:
x-amzn-ErrorMessage:Missing required parameter Session
x-amzn-ErrorType:InvalidParameterException:
Wrapping the cognitoUser.sendMFACode call in a cognitoUser.getSession() doesn't seem to work.
It's probably due to calling the sendMFACode function from out of the authenticateUser scope.
I can't figure out how to fix this, any ideas?
Never mind, I resolved this issue. I included a call to userPool.getCurrentUser(), which was not supposed to be there. The result of this function was a previously logged in user, when MFA was not activated.
@ZwaarContrast should the issue be closed then?
Yes this should be closed, excuse me for this non-issue.
For anyone coming here in the future via Google: My mistake was assuming that when calling authenticateUser, when MFA is required, the user will be stored and can be gotten again with cognitoUser = userPool.getCurrentUser();. This is not the case.
If you have sending authenticateUser and sendMFA in different functions (unlike the example), you need to call these functions on the same cognitoUser, to which you would need to keep a reference to.
Hi , I do see this issue still happening, I have mfa flow from login and i try to confirm the code
cognitoUser.sendMFACode(code, callback)
I always get exception InvalidParameterException: Missing required parameter Session , Btw, this is used in context of a Lambda not in client side Javascript
Any pointers on this is appreciated
Most helpful comment
Yes this should be closed, excuse me for this non-issue.
For anyone coming here in the future via Google: My mistake was assuming that when calling authenticateUser, when MFA is required, the user will be stored and can be gotten again with
cognitoUser = userPool.getCurrentUser();. This is not the case.If you have sending authenticateUser and sendMFA in different functions (unlike the example), you need to call these functions on the same cognitoUser, to which you would need to keep a reference to.