How to confirm user in Cognito User Pools without verifying email or phone?
Solution 1
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
}
Solution 2
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.
Solution 3
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:
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.
Related videos on Youtube
Dmitry Grinko
Updated on June 04, 2022Comments
-
Dmitry Grinko almost 2 years
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?
-
Robinson Calderón about 3 yearsyou can also use this by skipping the otp step they mention stackoverflow.com/a/66267032/8782229
-
-
Cliff Helsel about 5 yearsI've added this Lambda and my users are auto confirmed. Will this allow a user to use their IAM credentials for S3, etc? Can I then prompt the user to "verify your email address" and restrict access to functionality until the email is verified?
-
pvpkiran over 4 yearsThis does not work if you create a user using the sdk. It only works if user signsup through custom UI. Do you have a solution?
-
SeanMC about 3 yearsBut how do you add a pre-signup lambda function?
-
Pablo Papalardo about 2 yearsBest answer. Now my users can login but after I will want email confirmation