AWS Amplify – how to auto-verify email on sign up

Step 1. Add a lambda function using amplify add function command

 ? amplify add function
 ? Select which capability you want to add: Lambda function (serverless function)
 ? Provide an AWS Lambda function name: signUp
 ? Choose the runtime that you want to use: NodeJS
 ? Choose the function template that you want to use: Hello World
 Available advanced settings:
 - Resource access permissions
 - Scheduled recurring invocation
 - Lambda layers configuration 
 ? Do you want to configure advanced settings? No
 ? Do you want to edit the local lambda function now? No
 Successfully added resource signUp locally.

Step 2: Update index.js of the function with the following content


exports.handler = (event, context, callback) => {
    // Set the user pool autoConfirmUser flag after validating the email domain
    event.response.autoConfirmUser = true;
    event.response.autoVerifyEmail = true;

    // Return to Amazon Cognito
    callback(null, event);
};

Step 3: Run amplify push to push the lambda code to AWS

Step 4: Go to AWS console -> Go to Cognito

Step 5: Select the user pool

Step 6: Go to General settings -> Triggers

Step 7: Select the newly created signUp lambda function for the Pre Sign-Up dropdown.

The above set up will make sure that the user’s email address is auto-verified on sign up.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *