Hi,
I created the following lambda to customize the forgot password message.
I am willing to use the SAME message for the case of a user created directly on the Cognito user pool interface, but despite the fact that the correct event is called, the user does NOT receive the message I have configured.
So,
- if the event.triggerSource is CustomMessage_ForgotPassword: I enter the "if condition" and log the temporary code and email and the custom message is sent with the custom subject
- if the event.triggerSource is CustomMessage_AdminCreateUser: I enter the "if condition" and log the temporary code and email but then Cognito default message is used but with the custom subject
exports.handler = (event, context, callback) => {
console.log("EVENT", event);
if (event.triggerSource === "CustomMessage_ForgotPassword" ||
event.triggerSource === "CustomMessage_AdminCreateUser") {
const { codeParameter } = event.request;
const { email } = event.request.userAttributes;
const encodedEmail = encodeURIComponent(email);
console.log("EMAIL", encodedEmail)
console.log("PARAM", codeParameter)
const link = `http://localhost:3000/sign-in/password-confirmation?email=${encodedEmail}&code=${codeParameter}`;
event.response.emailSubject = "Reset your password";
event.response.emailMessage = `<body >AWS
<div
style="
background-color: #fff;
padding: 30px;
text-align: center;
font-size: 18px;
font-family: Arial, Helvetica, sans-serif;
color: #2e4057">
<p>
<span style="font-size: 30px; font-weight: bold">Hi!</span>
Forgot your password?
</p>
<br /><br />
<a
href=${link}
target="_blank"
>RESET PASSWORD</a
>
<br /><br />
<p>
Thank you
</p>
</div>
</body>`;
}
// CallBack to the lambda for the email trigger
callback(null, event);
};