Dmitry Grinko
Dmitry Grinko

Reputation: 15204

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

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?

Upvotes: 28

Views: 25911

Answers (4)

Trystan Loke
Trystan Loke

Reputation: 1

In case any one having hard time to find out where to add trigger for cognito in the new AWS console UI.

It is located at: User Pools > User pool properties > Lambda triggers

Upvotes: 0

boy
boy

Reputation: 483

I think the accepted answer is problematic. OP's question is how to confirm a user without verifying their email. But the solution will verify the user's email.

If you want to confirm a user with an unverified email (or phone), you can use AdminConfirmSignUpCommand. It is the intended way to confirm a user without having them do it, as per official docs:

enter image description here

Unlike ConfirmSignUpCommand, AdminConfirmSignUpCommand doesn't need a code. You can implement this command after signup in your API or as a Custom Message Trigger (effectively confirming the user when the email is sent).

Now, the user can log in, but the email must be confirmed still.

Upvotes: 11

Ula
Ula

Reputation: 2748

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.

Upvotes: 45

Abdennour TOUMI
Abdennour TOUMI

Reputation: 93193

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
}

Upvotes: 20

Related Questions