Search code examples
node.jsreactjsamazon-cognitoaws-amplify

how to change the email or password of user as admin in aws amplify for node.js


Everyone. I am developing using react app with aws amplify. For user authentication, I am using aws cognito. After I create user account by admin account on cognito, I can't change email and password of user as admin on there yet. How can I do for this?


Solution

  • You can do it the below way. But make sure that while configuring the cognito, the below fields[fields that you want to change] are set Mutable. Please follow these two links they might help more (Congito Attributes) & (adminUpdateUserAttributes).

    var params = {
      UserPoolId: '',//YOUR UserPoolID
      Username: '',//username
      UserAttributes: [
        {
          Name: "email",
          Value: ``,//NEW Email
        },
        {
          Name: "name",
          Value: ``,//New Name
        },
        {
          Name: "phone_number",
          Value: ``,//New Phone
        },
      ],
    };
    const cognitoClient = new AWS.CognitoIdentityServiceProvider();
    var createPromise = cognitoClient.adminUpdateUserAttributes(params).promise();
    await createPromise;