- Newest
- Most votes
- Most comments
The issue you're experiencing with Cognito refusing to verify updated email addresses with an email link is due to a combination of configuration settings and the way Cognito handles attribute updates.
First, it's important to note that the behavior you're seeing where a verification code is sent instead of a link when updating an email address is expected. This is because Cognito treats attribute updates differently from initial verification during sign-up.
To address your specific concerns:
-
For initial sign-up verification, your configuration using
emailStyle: cognito.VerificationEmailStyle.LINK
in theuserVerification
section is correct for sending a link. -
For attribute updates (like changing an email address), Cognito by default uses a code-based verification. This is why you're seeing a code sent even though you've configured link-based verification for sign-up.
-
The error you're encountering when trying to override this behavior with the L1/Cfn construct is due to an incorrect placeholder in your email message template. Cognito expects the
{####}
placeholder for both code and link-based verifications.
To resolve this issue and achieve your desired behavior:
-
Keep your L2 construct configuration as is for the initial sign-up verification.
-
For attribute updates, modify your L1/Cfn override as follows:
cfnUserPool.verificationMessageTemplate = { defaultEmailOption: 'CONFIRM_WITH_LINK', emailMessage: `Please click the following link to verify your new email address:\n\n{##Verify Your Email##}`, emailSubject: `Verify your new email address for ${props.domain}`, emailMessageByLink: `Please click the following link to verify your new email address:\n\n{##Verify Your Email##}`, emailSubjectByLink: `Verify your new email address for ${props.domain}`, };
Note the change in the placeholder from {####}
to {##Verify Your Email##}
. This is the correct format for link-based verification.
- Keep the
userAttributeUpdateSettings
configuration as you have it:
cfnUserPool.userAttributeUpdateSettings = { attributesRequireVerificationBeforeUpdate: ['email'], };
This ensures that email updates require verification before being applied.
With these changes, Cognito should send a verification link instead of a code when users update their email address. Remember that the actual text between the ##
in the placeholder can be customized, but the format must be {##Your Custom Text##}
.
If you continue to experience issues, double-check your Cognito User Pool settings in the AWS Console to ensure all configurations align with your CDK deployment.
Sources
UserAttributeUpdateSettingsType - Amazon Cognito User Pools
Configuring verification and invitation messages - Amazon Cognito
CfnUserPool.UserAttributeUpdateSettingsProperty (AWS CDK 2.177.0 API)
Relevant content
- asked 7 months ago
- asked 2 months ago
- asked 2 years ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 10 months ago
No this results in the same error: {##Verify Your Email##}' at 'verificationMessageTemplate.emailMessage' 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]* (Service: CognitoIdentityProvider, Status Code: 400, Request ID: 60f669a6-e741-4bce-96fb-45f22e816a3e) (SDK Attempt Count: 1)" (RequestToken: 8889d132-0f6f-c611-ed45-6b0946d7a5e0, HandlerErrorCode: InvalidRequest)