Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NotAuthorizedException when send verification code using Cognito with React

I've create an React application using AWS Amplify, and I getting and error with recover password feature.

When I put e-mail and call forgot password function, I'm receiving status code 400 with message: NotAuthorizedException: Contact administrator to reset password.

I checked my App Role, and I have "cognito-idp:AdminResetUserPassword" permission.

That's my code:

const sendCode = (event,email) => {
    event.preventDefault();

    const cognitoUser = new CognitoUser({
        Username: email.toLowerCase(),
        Pool: UserPool
    });

    // call forgotPassword on cognitoUser
    cognitoUser.forgotPassword({
        onSuccess: function(result) {
            alert(`Verification code sent to: ${email}!`)
        },
        onFailure: function(err) {
            alert(`Error while send verification code to: ${email} - ${err}`);
        },
    });
}

How can I get that permission?

like image 226
Rodrigo Ferreira Avatar asked Jul 20 '26 16:07

Rodrigo Ferreira


2 Answers

I solved this problem, and the solution is simple. The feature of recover accounts was disable, I just enable it and it works.

like image 112
Rodrigo Ferreira Avatar answered Jul 23 '26 07:07

Rodrigo Ferreira


It means your account recovery is disabled in the user-pool.

You can use AWS Console to enable the Self-service account recovery. You can find this setting inside the User Account Recovery section of the Sign-in experience tab in your user-pool, through AWS Console. User Account Recovery

like image 40
Prince Chaudhary Avatar answered Jul 23 '26 06:07

Prince Chaudhary



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!