Amazon-cognito-identity-js: How to send email verification manually with link?

Created on 5 Sep 2017  路  7Comments  路  Source: amazon-archives/amazon-cognito-identity-js

I setup the automatic confirmation of email not to hang user in the signup-process too long.

But I could not find any way how to send the verification email afterwards (if I turned on the automatic confirmation option, the Cognito does not seem to send the verification email).

The official API (http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/CognitoIdentityServiceProvider.html#getUserAttributeVerificationCode-property) seems to only provide a way to send an email with verification code not a link.

Any tip?

Most helpful comment

Here is what I have for now.

exports.handler = function(event, context) {

if(event.userPoolId === "<userpoolid>") {
    if(event.triggerSource === "CustomMessage_SignUp") {
        event.response.smsMessage = "Welcome to the service. Your confirmation code is " + event.request.codeParameter;
        event.response.emailSubject = "Welcome to the service";
        event.response.emailMessage =  "Thank you for signing up. Please click the link below to confirm your email address. http://localhost:4200/authentication/confirm?code=" + event.request.codeParameter + "&username=" + event.request.userAttributes.email;
    }
}
context.done(null, event);

};

All 7 comments

The only option I could find was to use a lambda function triggered by Custom Message.

@ajaxon Thanks! I will look into that.

Specifically, you need to handle requests of "triggerSource":"CustomMessage_SignUp", and you must enrich the request with

"response":{
  "smsMessage":".......",
  "emailMessage":".........",
  "emailSubject":"........."
}

and return the enriched request as a response. If the lambda takes too long to respond, Cognito will send the default verification message instead.

Here is what I have for now.

exports.handler = function(event, context) {

if(event.userPoolId === "<userpoolid>") {
    if(event.triggerSource === "CustomMessage_SignUp") {
        event.response.smsMessage = "Welcome to the service. Your confirmation code is " + event.request.codeParameter;
        event.response.emailSubject = "Welcome to the service";
        event.response.emailMessage =  "Thank you for signing up. Please click the link below to confirm your email address. http://localhost:4200/authentication/confirm?code=" + event.request.codeParameter + "&username=" + event.request.userAttributes.email;
    }
}
context.done(null, event);

};

@ajaxon I'll give it a try! Thanks!

@ohtangza Did you get this working? Kinda have the same issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sarah-pixvana picture sarah-pixvana  路  5Comments

tranan89 picture tranan89  路  5Comments

johnf picture johnf  路  3Comments

kaihendry picture kaihendry  路  4Comments

carlnordenfelt picture carlnordenfelt  路  5Comments