由于某种原因确认代码未交付给用户的情况下,我在重新发送确认代码时遇到问题。这是我所拥有的:
首先,我有一个注册步骤:
const cognito = new AWS.CognitoIdentityServiceProvider({region});
const params = {
ClientId,
Username,
Password,
};
const result = await cognito.signUp(params).promise();
此步骤(如果成功(应向用户的电子邮件地址(也是其用户名(发送一封电子邮件,其中包含其确认代码。现在让我们假设由于某种原因没有发送电子邮件(原因本身并不重要(。我想为用户提供一个请求发送新电子邮件的机会。到目前为止,这些是我一直为此目的进行测试的内容:
首先,我测试了resendConfirmationCode
方法:
const cognito = new AWS.CognitoIdentityServiceProvider({region});
const params = {
ClientId,
Username,
};
const result = await cognito.resendConfirmationCode(params).promise();
执行此代码会引发以下错误消息:
UnhandledPromiseRejectionWarning: NotAuthorizedException: Cannot resend codes. Auto verification not turned on.
然后,我测试了这种方法(因为这篇文章中给出的答案(:
const cognito = new AWS.CognitoIdentityServiceProvider({region});
const params = {
UserPoolId,
Username,
DesiredDeliveryMediums: ["EMAIL"],
ForceAliasCreation: false,
MessageAction: "RESEND",
}
const result = await cognito.adminCreateUser(params).promise();
这次,我收到此错误:
UnhandledPromiseRejectionWarning: UnsupportedUserStateException: Resend not possible. ********-****-****-****-********** status is not FORCE_CHANGE_PASSWORD
缩回的部分是用户的子。
那么,有谁知道我如何为尚未确认的用户重新发送确认代码?
对于可能遇到此问题的任何其他人来说,这是因为用户池的设置首先不是发送验证码。以下是在用户池上启用发送验证码的方法:
- 转到Coginto和用户池
- 转到"MFA 和验证"页面
- 在"您要验证哪些属性?"部分中,选择其中一个项目(对我来说是"电子邮件"(
但对我来说,实际问题是这个选项最初是早些时候正确设置的。但是当我执行此命令时,它被重置为"无验证":
aws cognito-idp update-user-pool
--region us-east-1
--user-pool-id us-east-1_*********
--lambda-config CustomMessage=arn:aws:lambda:us-east-1:************:function:composeEmail
此命令应该引入一个 lambda 函数来撰写验证码的电子邮件。但是由于某种原因,它也会重置其他设置,我不知道为什么。
无论如何,一旦您正确设置了该设置,我的第一个解决方案将起作用:
const cognito = new AWS.CognitoIdentityServiceProvider({region});
const params = {
ClientId,
Username,
};
const result = await cognito.resendConfirmationCode(params).promise();
与 AWS 支持人员聊天后,您可以指定验证属性,如下所示:
AWS Cognito-IDP 更新用户池 \ --区域美国东部-1 \ --user-pool-id us-east-1_********* \ --lambda-config CustomMessage=arn:aws:lambda:us-east-1:************:function:composeEmail --自动验证属性电子邮件