AWS Cognito: How do I handle a PasswordResetRequiredException

I clicked “Reset Password” in Cognito, and now when I log in, I get a “ PasswordResetRequiredException ”, how can I do this? I can’t find anything in the docs that tell me what should I do?

+7
source share
4 answers

I think that a specific user should have sent an email or SMS (if their email address or phone number has been verified). This letter should contain a code that you can use with ConfirmForgotPassword

+1
source

You will need to call the newPasswordRequired callback to authenticate the user, for example below:

 cognitoUser.authenticateUser(authenticationDetails, { onSuccess: function (result) { // User authentication was successful }, onFailure: function(err) { // User authentication was not successful }, mfaRequired: function(codeDeliveryDetails) { // MFA is required to complete user authentication. // Get the code from user and call cognitoUser.sendMFACode(mfaCode, this) }, newPasswordRequired: function(userAttributes, requiredAttributes) { // User was signed up by an admin and must provide new // password and required attributes, if any, to complete // authentication. // the api doesn't accept this field back delete userAttributes.email_verified; // Get these details and call cognitoUser.completeNewPasswordChallenge(newPassword, userAttributes, this); } }); 
0
source

I figured out how you can handle this with the (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 } } }); 
0
source

Source: https://habr.com/ru/post/1267310/


All Articles