Felix
Felix

Reputation: 5629

aws cognito verification email using parameters

can I use email as parameter in aws cognito verification email?

tried this:

You can verify your account here: <a href="http://localhost:8080/{####}/{email}">verification Link</a>

{####} works fine bute {email} not

thanks

Upvotes: 1

Views: 3325

Answers (2)

iarroyo
iarroyo

Reputation: 2444

Choose the lambda function which is going to trigger your custom messages, in my case is CognitoCustomMessage:

enter image description here

Inside this lambda function you can get the "email", "name", etc from your userAttributes like:

if(event.triggerSource === "CustomMessage_SignUp") {
  const { codeParameter, userAttributes: { name, email } } = event.request;

  event.response.emailSubject = "Welcome to ...";
  event.response.emailMessage = `Welcome ${name}, this is your verification 
  code ${codeParameter}.`;
}

See a complete list of AWS Lambda Triggers

Upvotes: 4

Vasileios Lekakis
Vasileios Lekakis

Reputation: 5572

I understand that you are referring to the "{email}" as a placeholder that Cognito will recognize and replace the value of the email for that user. So if you mean this is not supported.

However, Cognito provides a way through lambda to customize your verification message. Here are the details

It is easier to create a dynamic FQDN in the lambda trigger - so the developer can place the email at the appropriate place the message (or uri)

Here's an example of a custom message lambda function

exports.handler = function(event, context) {
// 
if(event.userPoolId === "theSpecialUserPool") {
    // Identify why was this function invoked
    if(event.triggerSource === "CustomMessage_SignUp") {
        // Ensure that your message contains event.request.codeParameter. This is the placeholder for code that will be sent
        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. " + event.request.codeParameter + " is your verification code";
    }
    // Create custom message for other events
}
// Customize messages for other user pools

//

// Return result to Cognito
context.done(null, event);
};

Upvotes: 2

Related Questions