Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aws-cognito: Cannot customise "Verify email" string in emailBody of UserPool userVerification #23828

Closed
fdansey-ostmodern opened this issue Jan 25, 2023 · 8 comments · Fixed by #28832
Assignees
Labels
@aws-cdk/aws-cognito Related to Amazon Cognito bug This issue is a bug. effort/small Small work item – less than a day of effort p2

Comments

@fdansey-ostmodern
Copy link

Describe the bug

When I change the text in the "{##Verify Email##}" placeholder, e.g. to "{##verify your email##}", cdk synth and cdk deploy commands yield the error,

Error: Verification email body must contain the template string '{##Verify Email##}'

This is incorrect as that documentation states that this string may be customised.
https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pool-settings-email-verification-message-customization.html

Help text in the AWS Cognito console reads:

You can customize this message with HTML. "Verify email" is the text that will be displayed over the clickable link in the message. You can customize the "Verify email" string, but the variable - some text enclosed by "{##" and "##}" - must be kept in the message.

Expected Behavior

I am able to change the emailBody property of a UserPool to include the placeholder of format, "{##Verify Your Email##}" with any custom string allowed by AWS Cognito.

Current Behavior

cdk synth and cdk deploy commands yield the error,

Error: Verification email body must contain the template string '{##Verify Email##}'
at UserPool.verificationMessageConfiguration (/node_modules/aws-cdk-lib/aws-cognito/lib/user-pool.js:1:10661)
at new UserPool (/node_modules/aws-cdk-lib/aws-cognito/lib/user-pool.js:1:4946)
at new BlarnStack (/blarn-stack/blarn-stack.ts:75:22)
at Object. (/stack-blarn.ts:12:1)
at Module._compile (node:internal/modules/cjs/loader:1218:14)
at Module.m._compile (/node_modules/ts-node/src/index.ts:1455:23)
at Module._extensions..js (node:internal/modules/cjs/loader:1272:10)
at Object.require.extensions. [as .ts] (/node_modules/ts-node/src/index.ts:1458:12)
at Module.load (node:internal/modules/cjs/loader:1081:32)
at Function.Module._load (node:internal/modules/cjs/loader:922:12)

Reproduction Steps

Create a stack containing a cognito.UserPool resource with property,

userVerification: {
  emailSubject: "Please verify your email",
  emailBody: `<p>Hello Hottie Pingi!</p>
<p>Please {##verify your email address##}</p>`,
  emailStyle: cognito.VerificationEmailStyle.LINK,
}

Run cdk synth on the stack.

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.61.0 (build 34f4926)

Framework Version

No response

Node.js Version

v18.13.0

OS

Ubuntu 22.04.1 LTS

Language

Typescript

Language Version

No response

Other information

No response

@fdansey-ostmodern fdansey-ostmodern added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jan 25, 2023
@github-actions github-actions bot added the @aws-cdk/aws-cognito Related to Amazon Cognito label Jan 25, 2023
@pahud
Copy link
Contributor

pahud commented Jan 30, 2023

Thank you for your report.

Can you provide a minimal CDK app so I can deploy in my account and reproduce this issue?

@pahud pahud added needs-reproduction This issue needs reproduction. and removed needs-triage This issue or PR still needs to be triaged. labels Jan 30, 2023
@pahud pahud self-assigned this Jan 30, 2023
@pahud pahud added the p2 label Jan 30, 2023
@fdansey-ostmodern
Copy link
Author

@pahud You can use a stack like this to reproduce the issue:

import {
  Stack,
  StackProps,
} from "aws-cdk-lib";
import { Construct } from "constructs";
import * as cognito from "aws-cdk-lib/aws-cognito";

export class BlarnStack extends Stack {
  constructor(
    scope: Construct,
    id: string,
    stackProps: StackProps
  ) {
    super(scope, id, stackProps);

    new cognito.UserPool(this, "Hottie" + "Pingi", {
      email: cognito.UserPoolEmail.withSES({
        fromEmail: `[email protected]`,
        fromName: "Charlie",
        replyTo: `[email protected]`,
        sesRegion: this.region,
        sesVerifiedDomain: "blarn.com",
      }),

      userVerification: {
        emailSubject: "Please verify your e-mail",
        emailBody: `<p>Welcome to blarn...</p>

<p>{##Custom Text##} and blarn your blarn blarn</p>`,
        emailStyle: cognito.VerificationEmailStyle.LINK,
      },
      accountRecovery: cognito.AccountRecovery.EMAIL_ONLY,
    });
  }
}

@pahud
Copy link
Contributor

pahud commented Feb 13, 2023

Yes you are right.

I think we have made it static here

const VERIFY_EMAIL_TEMPLATE = '{##Verify Email##}';

And we should change the logic here:

if (!Token.isUnresolved(emailMessage) && emailMessage.indexOf(VERIFY_EMAIL_TEMPLATE) < 0) {
throw new Error(`Verification email body must contain the template string '${VERIFY_EMAIL_TEMPLATE}'`);
}

I am making it a p2. Any PR contribution would be welcome and appreciated!

@pahud pahud added effort/small Small work item – less than a day of effort and removed needs-reproduction This issue needs reproduction. labels Feb 13, 2023
@pahud pahud removed their assignment Mar 2, 2023
@jadiaheno
Copy link

Hey @pahud, any update on this effort?

@antmarot
Copy link

I'm interested in this as well, any plan to fix this?

@jadiaheno
Copy link

Are you accepting PRs for this issue?

@GavinZZ
Copy link
Contributor

GavinZZ commented Jan 23, 2024

Drafted a PR to fix this issue, included the bug fix and updating README with some more examples on LINK type verification method.

@mergify mergify bot closed this as completed in #28832 Jan 25, 2024
mergify bot pushed a commit that referenced this issue Jan 25, 2024
When I change the text in the "{##Verify Email##}" placeholder, e.g. to "{##verify your email##}", cdk synth and cdk deploy commands yield the error,
```
Error: Verification email body must contain the template string '{##Verify Email##}'
```
This is incorrect as that documentation states that this string may be customised.
https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pool-settings-email-verification-message-customization.html

Help text in the AWS Cognito console reads:

    You can customize this message with HTML. "Verify email" is the text that will be displayed over the clickable link in the message. You can customize the "Verify email" string, but the variable - some text enclosed by "{##" and "##}" - must be kept in the message.

Expected Behavior

Be able to change the emailBody property of a UserPool to include the placeholder of format, "{##Verify Your Email##}" with any custom string allowed by AWS Cognito.

Closes #23828

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Vandita2020 pushed a commit to Vandita2020/aws-cdk that referenced this issue Jan 30, 2024
When I change the text in the "{##Verify Email##}" placeholder, e.g. to "{##verify your email##}", cdk synth and cdk deploy commands yield the error,
```
Error: Verification email body must contain the template string '{##Verify Email##}'
```
This is incorrect as that documentation states that this string may be customised.
https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pool-settings-email-verification-message-customization.html

Help text in the AWS Cognito console reads:

    You can customize this message with HTML. "Verify email" is the text that will be displayed over the clickable link in the message. You can customize the "Verify email" string, but the variable - some text enclosed by "{##" and "##}" - must be kept in the message.

Expected Behavior

Be able to change the emailBody property of a UserPool to include the placeholder of format, "{##Verify Your Email##}" with any custom string allowed by AWS Cognito.

Closes aws#23828

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
SankyRed pushed a commit that referenced this issue Feb 8, 2024
When I change the text in the "{##Verify Email##}" placeholder, e.g. to "{##verify your email##}", cdk synth and cdk deploy commands yield the error,
```
Error: Verification email body must contain the template string '{##Verify Email##}'
```
This is incorrect as that documentation states that this string may be customised.
https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pool-settings-email-verification-message-customization.html

Help text in the AWS Cognito console reads:

    You can customize this message with HTML. "Verify email" is the text that will be displayed over the clickable link in the message. You can customize the "Verify email" string, but the variable - some text enclosed by "{##" and "##}" - must be kept in the message.

Expected Behavior

Be able to change the emailBody property of a UserPool to include the placeholder of format, "{##Verify Your Email##}" with any custom string allowed by AWS Cognito.

Closes #23828

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-cognito Related to Amazon Cognito bug This issue is a bug. effort/small Small work item – less than a day of effort p2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants