Home > Mobile >  disable verification code being sent on email verification on cognito
disable verification code being sent on email verification on cognito

Time:10-01

userPool.signUp(
                userData.email,
                userData.password,
                attributeList,
                [],
                async (err, result) => {
                    if (err) {
                        failure(new HttpException(500, err.message));
                    }

                    let myCredentials = new AWS.CognitoIdentityCredentials({
                        IdentityPoolId: process.env.USER_POOL_ID!,
                    });
                    new AWS.Config({
                        credentials: myCredentials,
                        region: process.env.AWS_REGION,
                    });
                    let cognitoIdentityServiceProvider = new AWS.CognitoIdentityServiceProvider();
                    cognitoIdentityServiceProvider.adminConfirmSignUp(
                        {
                            UserPoolId: process.env.USER_POOL_ID!,
                            Username: userData.email,
                        },
                        function (err, _data) {
                            if (err) {
                                failure(err);
                            }

                            cognitoIdentityServiceProvider.adminUpdateUserAttributes(
                                {
                                    UserPoolId: process.env.USER_POOL_ID!,
                                    Username: userData.email,
                                    UserAttributes: [
                                        {
                                            Name: 'email_verified',
                                            Value: 'true',
                                        },
                                    ],
                                },
                                () => {
                                    console.log('done');
                                }
                            );
                        }
                    );

                    if (result) {
                        const cognitoUser = result.user;

                        success({ user: cognitoUser, sub: result.userSub });
                    } else {
                        failure(
                            new HttpException(
                                500,
                                'Authentication server error, please try again later'
                            )
                        );
                    }
                }
            );

This is the code by which I am signing up a user and auto verify that user on cognito. Problem being I have 2 different set of user roles, and one user i am auto confirming but for the other i want them to manually confirm, using the code that is sent by cognito.

Now for the one type of user for which the auto_confirmation is done the email and cofirm user is working perfectly, with one caveat. The code for verification is being sent even if it's auto verified by admincognito.

How can i disable this on this particualr set of code, so that the other user role can confirm with the code that is being sent via email

CodePudding user response:

Cognito isn't really configurable in this regard. Your escape hatch in this case is the lightly documented custom email sender lambda trigger. Perform whatever checks you want before sending the email through SES (or not).

CodePudding user response:

I solved this issue by creating a pre-signup lambda trigger. And passing in the role to it as a user attribute and then auto verifying email and user based on the role.

  • Related