Can change the user's email in aws cognito user pool?
Asked Answered
B

2

14

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?

Beekman answered 9/3, 2021 at 9:43 Comment(0)
L
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;
Lunate answered 9/3, 2021 at 10:2 Comment(0)
H
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

Heteropolar answered 13/9, 2022 at 14:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.