aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.65k stars 3.91k forks source link

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

Closed fdansey-ostmodern closed 9 months ago

fdansey-ostmodern commented 1 year ago

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

pahud commented 1 year ago

Thank you for your report.

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

fdansey-ostmodern commented 1 year ago

@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: `hello@blarn.com`,
        fromName: "Charlie",
        replyTo: `hello@blarn.com`,
        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 commented 1 year ago

Yes you are right.

I think we have made it static here

https://github.com/aws/aws-cdk/blob/64eb2bdb7126799e21bad03d668d91c7a501feb4/packages/%40aws-cdk/aws-cognito/lib/user-pool.ts#L1037

And we should change the logic here:

https://github.com/aws/aws-cdk/blob/64eb2bdb7126799e21bad03d668d91c7a501feb4/packages/%40aws-cdk/aws-cognito/lib/user-pool.ts#L1060-L1062

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

jadiaheno commented 1 year ago

Hey @pahud, any update on this effort?

antmarot commented 9 months ago

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

jadiaheno commented 9 months ago

Are you accepting PRs for this issue?

GavinZZ commented 9 months ago

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

github-actions[bot] commented 9 months ago

⚠️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.