NodeJS Cognito用户将电子邮件标记为已验证:“InvalidParameterException”

o75abkj4  于 2023-06-05  发布在  Node.js
关注(0)|答案(1)|浏览(188)

我正在尝试将用户添加到Cognito用户池。我想在创建它们时将其电子邮件标记为已验证,我在这里使用AdminCreateUserCommand。

const createUserCommand = new AdminCreateUserCommand({
            UserPoolId: process.env.COGNITO_POOL_ID,
            Username: user.email,
            TemporaryPassword: nanoid(10),
            UserAttributes: [
              {
                Name: "email_verified",
                Value: "true",
              },
            ],
          });
    
          const createUserResponse = await this.cognitoClient.send(
            createUserCommand
          );

但我得到以下错误:
{“error”:{“$metadata”:{“httpStatusCode”:400,“requestId”:“0 d 75da 0 d-53 f1 - 44 e3-ba 20 - 018 c903 d2 f8 a”,“尝试”:1,“totalRetryDelay”:0 },“name”:“InvalidParameterException”}
这里有什么问题?

6jygbczu

6jygbczu1#

是的,正如@derpirscher所说,它在添加电子邮件属性后得到了修复。新代码就像

const createUserCommand = new AdminCreateUserCommand({
        UserPoolId: process.env.COGNITO_POOL_ID,
        Username: user.email,
        TemporaryPassword: nanoid(10),
        UserAttributes: [
          {
            Name: "email",
            Value: user.email,
          },
          {
            Name: "email_verified",
            Value: "true",
          },
        ],
      });

谢谢

相关问题