15

I am using aws cognito user pool in my application and users can log in to the app using their email that verified in aws cognito. Users can change login email and the users must verify the new email. But users can't change login email in my application now, and I don't know how to solve it. We need to find a solution to update the email on the AWS cognito and fix it. How can change the user's email in aws cognito user pool?

2 Answers 2

8

You can use adminUpdateUserAttributes to update user email and email_verified after that Amazon Cognito sends email again (check here).

const params = {
  UserPoolId: 'UserPoolID',
  Username: 'username',
  UserAttributes: [
    {
      Name: "email",
      Value: "new email"
    },
    {
      Name: "email_verified",
      Value: "false"
    }
  ],
};
const cognitoClient = new AWS.CognitoIdentityServiceProvider();
const createPromise = cognitoClient.adminUpdateUserAttributes(params).promise();
await createPromise;
Sign up to request clarification or add additional context in comments.

Comments

4

You can use UpdateUserAttribute to update the email

 const params = {
        AccessToken: accessToken, /* required */
        UserAttributes: [ /* required */
            {
                Name: 'email', /* required */
                Value: email
            }
       }; 

        const response = await cognito.updateUserAttributes(params).promise();

later, you will need to confirm this change using this method VerifyUserAttribute

const params = {
        AccessToken: accessToken, /* required */
        AttributeName: attributeName, /* required */
        Code: code /* required */
    };
    try {
        const response = await cognito.verifyUserAttribute(params).promise();

This is the best way to change email or some others attributes

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.