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?
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?
4 Answers
Reset to default 4check this http://docs.aws.amazon./cognito/latest/developerguide/cognito-user-pools-using-import-tool-password-reset.html
you need to call ForgotPassword()...
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
}
}
});
I think that the specific user should have had an email or sms sent to them (if their email or phone number had been verified). In this email there should be a code which you can use with ConfirmForgotPassword
You would have to implement the newPasswordRequired callback for authenticateUser such as 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 plete 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 plete
// authentication.
// the api doesn't accept this field back
delete userAttributes.email_verified;
// Get these details and call
cognitoUser.pleteNewPasswordChallenge(newPassword, userAttributes, this);
}
});