[英]How to resend confirmation code in Cognito's sign-up process
I'm having issues with resending the confirmation code for cases where for some reason the confirmation code was not delivered to the users.对于由于某种原因未将确认码发送给用户的情况,我在重新发送确认码时遇到问题。 This is what I have:
这就是我所拥有的:
First, I have a sign-up step:首先,我有一个注册步骤:
const cognito = new AWS.CognitoIdentityServiceProvider({region});
const params = {
ClientId,
Username,
Password,
};
const result = await cognito.signUp(params).promise();
This step (in case of success) should send an email to the user's email address (which is also their username) with their confirmation code.此步骤(如果成功)应向用户的 email 地址(也是他们的用户名)发送 email 及其确认码。 Now let's assume for some reason that email is not sent (the reason itself is not important).
现在让我们假设由于某种原因没有发送 email(原因本身并不重要)。 I would like to provide a chance to the user to ask for a new email to be sent.
我想为用户提供一个机会来要求发送一个新的 email。 These are what I've been testing for this purpose so far:
到目前为止,这些是我为此目的而测试的:
First, I've tested the resendConfirmationCode
method:首先,我测试了
resendConfirmationCode
方法:
const cognito = new AWS.CognitoIdentityServiceProvider({region});
const params = {
ClientId,
Username,
};
const result = await cognito.resendConfirmationCode(params).promise();
Executing this code throws this error message:执行此代码会引发此错误消息:
UnhandledPromiseRejectionWarning: NotAuthorizedException: Cannot resend codes. Auto verification not turned on.
Then, I tested this approach (because of the answer given in this post ):然后,我测试了这种方法(因为在这篇文章中给出了答案):
const cognito = new AWS.CognitoIdentityServiceProvider({region});
const params = {
UserPoolId,
Username,
DesiredDeliveryMediums: ["EMAIL"],
ForceAliasCreation: false,
MessageAction: "RESEND",
}
const result = await cognito.adminCreateUser(params).promise();
This time, I'm getting this error:这一次,我收到了这个错误:
UnhandledPromiseRejectionWarning: UnsupportedUserStateException: Resend not possible. ********-****-****-****-********** status is not FORCE_CHANGE_PASSWORD
The retracted part is the user's sub.收回的部分是用户的潜艇。
So, does anyone know how I can resend the confirmation code for a user that is not confirmed yet?那么,有谁知道我如何为尚未确认的用户重新发送确认码?
For anyone else who might be facing this issue, this was because the User Pool's setting was not to sent the verification code in the first place.对于可能遇到此问题的其他任何人,这是因为用户池的设置首先不是发送验证码。 Here's how to enable sending the verification code on User Pool:
以下是在用户池上启用发送验证码的方法:
But the actual issue for me was that this option was initially set properly earlier.但对我来说实际问题是这个选项最初是在早些时候正确设置的。 But it was reset to "No verification" when I executed this command:
但是当我执行这个命令时它被重置为“无验证”:
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
This command is supposed to introduce a lambda function to compose the email for verification code.该命令应该引入一个 lambda function 来组成 email 用于验证码。 But for some reason, it will reset the other setting as well and I have no idea why.
但由于某种原因,它也会重置其他设置,我不知道为什么。
In any case, once you have that setting set properly, my first solution will work:无论如何,一旦您正确设置了该设置,我的第一个解决方案将起作用:
const cognito = new AWS.CognitoIdentityServiceProvider({region});
const params = {
ClientId,
Username,
};
const result = await cognito.resendConfirmationCode(params).promise();
After a chat with AWS support, you can specify verification attribute like this:与 AWS 支持人员聊天后,您可以指定验证属性,如下所示:
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--auto-verified-attributes email
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.