aws-amplify / aws-amplify/amplify-cli

Auth CustomMessage Lambda: Email message HTML not rendering correctly for CustomMessage_AdminCreateUser event

Open
#12,911 5 comments 0 reactions 0 assignees View on GitHub
auth bug dependency-issue
Dominant language
TypeScript
Stars
2.9k
Forks
825
Avg merge
11d 23h
Merged PRs (30d)
2

Description

### How did you install the Amplify CLI?

_No response_

### If applicable, what version of Node.js are you using?

_No response_

### Amplify CLI Version

12.1.1

### What operating system are you using?

Mac

### Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.

Added Lambda Trigger Custom Message

```js
/* eslint-disable */
/**
* @type {import('@types/aws-lambda').CustomMessageTriggerHandler}
*/

function getEnv(env) {
return env == "prod" ? "app" : env;
}

exports.handler = async (event) => {
console.log(event);
const { email } = event.request.userAttributes;
const { codeParameter } = event.request;
const env = getEnv(process.env.ENV);
const baseLink = `http://${env}.appname.com`;

const generateHtml = (header, paragraph, link, linkText) => `


${header}


${paragraph}


${linkText}

Ser du inte knappen ovan? Klistra in följande länk i din webbläsare: ${link}


Med vänliga hälsningar,
AppName




`;

if (event.triggerSource === "CustomMessage_SignUp") {
const header = "Välkommen till AppName";
const paragraph = "Din registreringsbegäran godkändes framgångsrikt. Klicka nedan för att slutföra registreringen.";
const linkText = "KLICKA HÄR FÖR ATT VERIFIERA DIN E-POST";
const link = `${baseLink}/verify-account/${email}/${codeParameter}/true`;

event.response = {
emailSubject: "Välkommen till AppName | Verifiera din email",
emailMessage: generateHtml(header, paragraph, link, linkText),
};
} else if (event.triggerSource === "CustomMessage_AdminCreateUser") {
const header = "Välkommen till AppName";
const paragraph = "En kollega har bjudit in dig till AppName. Klicka nedan för att registrera dig.";
const linkText = "KLICKA HÄR FÖR ATT REGISTRERA DIG";
const link = `${baseLink}/sign-in/${email}/${codeParameter}`;

event.response = {
emailSubject: "AppName | Du har blivit inbjuden till AppName",
emailMessage: generateHtml(header, paragraph, link, linkText),
};
}

console.log(event.response);
return event;
};
```

### Describe the bug

I have encountered an issue where the HTML content is not rendering correctly in the email message when the event is triggered as "CustomMessage_AdminCreateUser". The code appears to be generating the HTML correctly, as I can see the expected HTML structure in the logs. However, when the email is received, the HTML content is not displayed properly.

The generated HTML content is not rendering properly in the email message for the CustomMessage_AdminCreateUser event.

I am getting the default Email Message "Your username is {username} and temporary password is {####}" but the Email Subject is changed as according to my code

Please note that this issue does not occur when the event is triggered as "CustomMessage_SignUp". In that case, the HTML content is correctly displayed in the email message.

### Expected behavior

The email message for the CustomMessage_AdminCreateUser event should display the generated HTML content correctly, including the header, paragraph, and button/link.

### Reproduction steps

To reproduce the issue, follow these steps:

1. Trigger the CustomMessage_AdminCreateUser event.
2. Check the received email and observe that the HTML content is not rendered correctly.

### Project Identifier

_No response_

### Log output

```
# Put your logs below this line

```

### Additional information

_No response_

### Before submitting, please confirm:

- [X] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
- [X] I have removed any sensitive information from my code snippets and submission.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.