如何在 aws amplify for node.js 中以管理员身份更改用户的电子邮件或密码

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

各位。 我正在使用带有 aws amplify 的 React 应用程序进行开发。 对于用户身份验证,我使用的是 aws cognito。 在 Cognito 上通过管理员帐户创建用户帐户后,我无法在那里以管理员身份更改用户的电子邮件和密码。 我该怎么做?

您可以通过以下方式进行。但请确保在配置 cognito 时,将以下字段 [您要更改的字段] 设置为可变。请点击这两个链接,它们可能会有更多帮助 (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;