CDK: is there a way to activate Cognito email verification?

0

Hi! I'm working on an app which uses a passwordless auth solution (via emails). I configured my serverless infrastructure, everything works fine except one thing :(

My Cognito UserPool is ok but I wish to configure it with the option called "Allow Cognito to automatically send messages to verify and confirm". If I manually activate it, an email is automatically sent to the user with a verification link. This is exactly what I want. But I can't find a way to activate this system with the CDK framework (I use Javascript).

Is it possible? Thanks Thomas

The option I wish to activate with CDK

3 Antworten
0
Akzeptierte Antwort

autoVerify: { email: true, // <-- Change this to true },

profile picture
EXPERTE
beantwortet vor 7 Monaten
profile picture
EXPERTE
überprüft vor 7 Monaten
  • Damn, I used this config some days ago and maybe I did something wrong that day. Thank you so much it's perfect.

0

Yes, you can activate the "Allow Cognito to automatically send messages to verify and confirm" feature using the AWS CDK for your Cognito UserPool.

To enable the email verification in a Cognito UserPool using the AWS CDK in JavaScript, you should configure the autoVerifiedAttributes property and set up the email configuration for the UserPool.

const cdk = require('@aws-cdk/core');
const cognito = require('@aws-cdk/aws-cognito');

class CognitoStack extends cdk.Stack {
  constructor(scope, id, props) {
    super(scope, id, props);

    new cognito.UserPool(this, 'MyUserPool', {
      // Specify that email addresses are an account identifier and are auto-verified.
      signInAliases: {
        email: true
      },
      autoVerifiedAttributes: [cognito.UserPoolAttribute.EMAIL],

      // Email configuration
      email: {
        from: 'noreply@yourdomain.com', // replace with your "from" address
        replyTo: 'support@yourdomain.com' // replace with your "reply to" address
      },

      // ... (other UserPool configurations if any)
    });
  }
}

const app = new cdk.App();
new CognitoStack(app, 'CognitoStack');

Regards, Andrii

profile picture
EXPERTE
beantwortet vor 7 Monaten
profile picture
EXPERTE
überprüft vor 4 Monaten
0

Hi Andrii, Thank you for your answer. I guess your code is using the CDK version 1. I migrate to version 2 because it is said v1 is no longuer maintained :(

Here is my V2 code and I can't find any attribute like autoVerifiedAttributes:

const userPool = new UserPool(stack, "UserPool.Passwordless.Create", {
        removalPolicy: RemovalPolicy.RETAIN,
        userPoolName: `CGC-UserPool-Passwordless-${branchID}`,
        selfSignUpEnabled: true,
        autoVerify: {
            email: false,
        },
        signInAliases: {
            email: true,
        },
        userVerification: {
            emailSubject: "Votre lien de vérification ....",
            emailBody: "Bonjour, ... {##Verify Email##}.",
            emailStyle: VerificationEmailStyle.LINK,
        },
        standardAttributes: {
            email: {
                required: true,
                mutable: false,
            },
            nickname: {
                required: true,
                mutable: false,
            },
        },
    });

    userPool.addDomain("UserPoolDomain.Passwordless.Create", {
        cognitoDomain: {
            domainPrefix: "cgc-signup",
        },
    });
Thomas
beantwortet vor 7 Monaten
profile picture
EXPERTE
überprüft vor 4 Monaten

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen