简体   繁体   English

如何在 Cognito 的注册过程中重新发送确认码

[英]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:以下是在用户池上启用发送验证码的方法:

  1. Go to Coginto and the User Pool Go 到 Coginto 和用户池
  2. Go to the page "MFA and verifications" Go 到“MFA 和验证”页面
  3. In the section "Which attributes do you want to verify?"在“您要验证哪些属性?”部分中select one of the items (for me it was "Email") select 其中一项(对我来说是“电子邮件”)

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.

相关问题 拒绝 Cognito 用户池中的注册请求 - Denying a Sign-up request in Cognito User Pools 注册后禁用 Cognito email 确认 - Disable Cognito email confirmation after sign up 如何使用GoLang拒绝注册触发器 - How to reject sign-up trigger with GoLang AWS Cognito 托管的注册和登录页面的空白页面 - Empty page for the sign-up and sign-in pages hosted by AWS Cognito 是否存在适用于AWS Cognito Web应用程序(而非移动应用程序)的注册/登录GUI功能? - Is there a Sign-up/Sign-in GUI functionality for AWS Cognito web apps (not mobile apps)? AWS Cognito无需密码即可注册以获取电子邮件确认链接 - AWS Cognito sign up without password to get email confirmation link Cognito 从 Pre Sign-up Lambda 触发器发送什么样的事件 - What kind of event does Cognito send from Pre Sign-up Lambda Trigger 有没有办法通过 Amplify JS SDK 和 React 在 Cognito 托管 UI 中请求注册重定向? - Is there a way to request sign-up redirect in Cognito Hosted UI via Amplify JS SDK with React? AWS-Amplify 的注册问题 - Sign-Up issue with AWS-Amplify 为使用 AWS(特别是 S3 存储桶)托管的网站页面创建注册表单(类似于 mailchimp) - Creating a sign-up form (similar to mailchimp) for a website page that is hosted using AWS (S3 bucket specifically)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM