Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Cognito: How should I handle PasswordResetRequiredException

I have clicked "Reset Password" in Cognito and now when I login I get "PasswordResetRequiredException", how should I handle this? I cant find anything in the docs that tell me what should I do?

like image 620
Jiew Meng Avatar asked Apr 29 '17 08:04

Jiew Meng


Video Answer


2 Answers

check this http://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pools-using-import-tool-password-reset.html

you need to call ForgotPassword()...

like image 81
UXDart Avatar answered Sep 24 '22 20:09

UXDart


I figured out the exact way that you can handle this on (onFailure) callback:

// Create a cognito user instance
const cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData);
// Trigger to authenticate the user
cognitoUser.authenticateUser(authenticationDetails, { 
  onFailure: function(err) {
    if (err.code == "PasswordResetRequiredException") {
      // Confirm user data
      cognitoUser.confirmPassword(
        "", // Put your verification code here
        "", // Here is your new password
        {
          onSuccess: result => {
            // Everything worked as expected
          },
          onFailure: err => {
            // Trigger failure
          }
        }
      );
    } else {
      // Trigger failure
    }
  }
});
like image 39
caiobiodere Avatar answered Sep 23 '22 20:09

caiobiodere