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?
Can change the user's email in aws cognito user pool?
Asked Answered
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;
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
© 2022 - 2024 — McMap. All rights reserved.