Unexpected validation error for custom email message using ReactDOMServer.renderToStaticMarkup
See original GitHub issueDescribe the bug When I try to create a custom message using ReactDOMServer.renderToStaticMarkup, I get a validation error. However if I pass the value and regex into a regex tool, I get a match.
Error below:
1 validation error detected: Value '<html><body><div style="padding:20"><h4>Hi, there!</h4><p>Thank you for signing up to xxx. Here is the confirmation code {####} to complete your registration.</p><p> </p><p>--</p><p>Happy days,</p><p>CompanyName</p></div></body></html>' at 'emailBody' failed to satisfy constraint: Member must satisfy regular expression pattern: [\p{L}\p{M}\p{S}\p{N}\p{P}\s*]*\{####\}[\p{L}\p{M}\p{S}\p{N}\p{P}\s*]*
To Reproduce
I have a lambda that handles the CustomMessageTriggerEvent
events. It sets the event.response.emailSubject
and event.response.emailMessage
. The problem is with the emailMessage
field.
See code snippet below.
Expected behavior It should just work.
Code Snippet
event.response.emailMessage = getCustomEmailMessage(triggerSource, event.request.codeParameter);
calls:
const getCustomEmailMessage = (triggerSource: string, codeParameter: string): string => {
if (triggerSource === 'CustomMessage_SignUp') {
return getHtmlMessage(
`Thank you for signing up to CompanyName. Here is the confirmation code ${codeParameter} to complete your registration.`
);
} else {
//do something else
}
};
const getHtmlMessage = (textToInject: string): string => {
const reactComponent = renderEmailMessage(textToInject)
return "<html><body>" + reactComponent + "</body></html>"
//I have also tried using return`<html><body>${reactComponent}</body></html>`
};
The renderEmailMessage
is in EmailMessage.tsx
. The entire file is below:
import ReactDOMServer from "react-dom/server";
interface EmailMessageProps {
code: string;
}
const EmailMessage: React.FC<EmailMessageProps> = ({code}: EmailMessageProps) => (
<div style={{padding: "20"}}><h4>Hi, there!</h4><p>{code}</p><p> </p><p>--</p><p>Happy hacking,</p><p>CompanyName</p></div>
);
export const renderEmailMessage = (code: string) => {
return ReactDOMServer.renderToStaticMarkup(<EmailMessage code={code} />)
}
If instead of using react and I simply have the below in getHtmlMessage
, it works:
const getHtmlMessage = (textToInject: string): string => {
return `<html>
<body>
<div style="padding: 20;">
<h4>Hi, there!</h4><p>${textToInject}</p><p> </p><p>--</p><p>Happy hacking,</p><p>CompanyName</p>
</div>
</body>
</html>`;
};
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (4 by maintainers)
Top GitHub Comments
@amhinson why has this issue been closed without providing the link to the
AWS Cognito support
issue. I’m experiencing the same issue although I created the function for custom message withamplify
This issue has been automatically locked since there hasn’t been any recent activity after it was closed. Please open a new issue for related bugs.
Looking for a help forum? We recommend joining the Amplify Community Discord server
*-help
channels or Discussions for those types of questions.