Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to confirm user in Cognito User Pools without verifying email or phone?

Tags:

I am using Amazon Cognito Identity SDK for JavaScript (deprecated).

I created new pool without verifying email and phone_number.

By default, users aren't confirmed in Cognito User Pools, so I need to do this manually.

How to confirm user in Cognito User Pools without verifying email or phone?

like image 388
Dmitry Grinko Avatar asked Nov 18 '17 02:11

Dmitry Grinko


People also ask

How do I verify a Cognito user?

When a user updates their email address or phone number in your app, Amazon Cognito immediately sends a message with a verification code to a user if you configured your user pool to automatically verify that attribute. The user must then provide the code from the verification message to your app.

How do I verify my email in Cognito user pool?

Amazon Cognito can automatically verify email addresses or phone numbers. To do this verification, Amazon Cognito sends a verification code or a verification link. For email addresses, Amazon Cognito can send a code or a link in an email message. For phone numbers, Amazon Cognito sends a code in an SMS text message.

How do I mark an email as verified in Cognito?

In order to verify a cognito user's email, we have to set their email_verified attribute to true . To set their email_verified attribute to true we can use the admin-update-user-attributes command. Copied!

What does Cognito use to create unique identities and authorize users?

With a user pool, your app users can sign in through the user pool or federate through a third-party identity provider (IdP). Identity pools are for authorization (access control). You can use identity pools to create unique identities for users and give them access to other AWS services.


2 Answers

I hope this will help someone else.

To do this you can add this Lambda function:

exports.handler = (event, context, callback) => {     event.response.autoConfirmUser = true;     event.response.autoVerifyEmail = true;  // this is NOT needed if e-mail is not in attributeList     event.response.autoVerifyPhone = true;  // this is NOT needed if phone # is not in attributeList     context.done(null, event); }; 

Then navigate to AWS Cognito's General settings >> Triggers and add this Lambda function to 'Pre sign-up' - click the drop down list and select Lambda function with above code.

If you only use 'preferred_username' (if no e-mail or phone # is used) setting event.response.autoConfirmUser to true is sufficient.

like image 71
Ula Avatar answered Sep 21 '22 18:09

Ula


Actually, AWS has recently added the ability to verify email and verify phone number in the pre-signup lambda as well. You basically need to set autoVerifyEmail and autoVerifyPhone in the lambda and they will get verified. More info in the official documentation.

"response": {     "autoConfirmUser": boolean     "autoVerifyEmail": boolean     "autoVerifyPhone": boolean } 
like image 37
Abdennour TOUMI Avatar answered Sep 18 '22 18:09

Abdennour TOUMI