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

bug with Cognito,if you use Email MFA #14199

Closed
3 tasks done
KawashimaRyutaro opened this issue Feb 10, 2025 · 4 comments
Closed
3 tasks done

bug with Cognito,if you use Email MFA #14199

KawashimaRyutaro opened this issue Feb 10, 2025 · 4 comments
Labels
Auth Related to Auth components/category question General question

Comments

@KawashimaRyutaro
Copy link

Before opening, please confirm:

JavaScript Framework

Angular

Amplify APIs

Authentication

Amplify Version

v6

Amplify Categories

No response

Backend

None

Environment information

  System:
    OS: Windows 10 10.0.19045
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
    Memory: 2.22 GB / 15.73 GB
  Binaries:
    Node: 20.14.0 - C:\Progra~1\nodejs\node.EXE
    Yarn: 1.22.19 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 10.7.0 - C:\Progra~1\nodejs\npm.CMD
  Browsers:
    Edge: Chromium (131.0.2903.70)
  npmPackages:
    @angular-devkit/build-angular: ^19.0.7 => 19.0.7
    @angular/animations: ^19.0.0 => 19.0.5
    @angular/cdk: ^19.1.1 => 19.1.1
    @angular/cli: ^19.0.6 => 19.0.6
    @angular/common: ^19.0.0 => 19.0.5
    @angular/compiler: ^19.0.0 => 19.0.5
    @angular/compiler-cli: ^19.0.0 => 19.0.5
    @angular/core: ^19.0.0 => 19.0.5
    @angular/forms: ^19.0.0 => 19.0.5
    @angular/material: ^19.1.1 => 19.1.1
    @angular/platform-browser: ^19.0.0 => 19.0.5
    @angular/platform-browser-dynamic: ^19.0.0 => 19.0.5
    @angular/router: ^19.0.0 => 19.0.5
    @eslint/js: ^9.17.0 => 9.17.0
    @types/jasmine: ~5.1.0 => 5.1.5
    amazon-cognito-identity-js: ^6.3.12 => 6.3.12
    amazon-cognito-identity-js/internals:  undefined ()
    angular-eslint: 19.0.2 => 19.0.2
    aws-sdk: ^2.1692.0 => 2.1692.0
    eslint: ^9.16.0 => 9.17.0
    globals: ^15.14.0 => 15.14.0 (11.12.0, 14.0.0)
    jasmine-core: ~5.4.0 => 5.4.0 (4.6.1)
    karma: ~6.4.0 => 6.4.4
    karma-chrome-launcher: ~3.2.0 => 3.2.0
    karma-coverage: ~2.2.0 => 2.2.1
    karma-coverage-coffee-example:  1.0.0
    karma-jasmine: ~5.1.0 => 5.1.0
    karma-jasmine-html-reporter: ~2.1.0 => 2.1.0
    ng-packagr: ^19.0.0 => 19.0.1
    rxjs: ~7.8.0 => 7.8.1
    rxjs/ajax:  undefined ()
    rxjs/fetch:  undefined ()
    rxjs/operators:  undefined ()
    rxjs/testing:  undefined ()
    rxjs/webSocket:  undefined ()
    tslib: ^2.3.0 => 2.8.1 (1.14.1)
    typescript: ~5.6.2 => 5.6.3
    typescript-eslint: 8.18.0 => 8.18.0
    zone.js: ~0.15.0 => 0.15.0
  npmGlobalPackages:
    @angular/cli: 19.0.6
    corepack: 0.28.1
    esbuild: 0.24.0
    npm: 10.7.0


Describe the bug

I create Cognito Userpool.
When I authenticate User, The following error occurs.
But I can get authentication code Email.

Error

core.mjs:6643 
 ERROR TypeError: Cannot read properties of undefined (reading 'NewDeviceMetadata')
    at CognitoUser2.authenticateUserInternal (CognitoUser.js:407:67)
    at CognitoUser.js:294:27
    at CognitoUser.js:277:22
    at Client.js:188:31
    at _ZoneDelegate.invoke (zone.js:369:28)
    at Object.onInvoke (core.mjs:6495:25)
    at _ZoneDelegate.invoke (zone.js:368:34)
    at ZoneImpl.run (zone.js:111:43)
    at zone.js:2538:40
    at _ZoneDelegate.invokeTask (zone.js:402:33)
handleError	@	core.mjs:6643

Expected behavior

No errors.
totpRequired is set in returnData[“type”].

Reproduction steps

1.Execute sentVerificationCode

Code Snippet

static async sentVerificationCode(username: string, password: string): Promise<any> {

  const userData:ICognitoUserData = {
    Username: username,
    Pool: CognitoService.userPool,
    Storage: localStorage
  };
  const cognitoUser = new CognitoUser(userData);
  const authenticationData:IAuthenticationDetailsData = {
    Username: username,
    Password: password,
  };

  const authenticationDetails = new AuthenticationDetails(authenticationData);
  let returnData = {
    type:"None",
    Session:"",
  };
  try
  {

    const authResult = new Promise((resolve, reject) => {
      cognitoUser.authenticateUser(authenticationDetails, {
        onSuccess(result) {
          returnData["type"] = "success";
          resolve(result);
        },
        mfaSetup(challengeName, challengeParameters) {
          returnData["type"] = "mfa";
        },
        onFailure(err) {
          returnData["type"] = "failure";
          console.log(err);
          reject(err);
        },
        totpRequired(challengeName, challengeParameters) {
          returnData["type"] = "totpRequired";
        },
        newPasswordRequired(userAttributes, requiredAttributes) {
          returnData["type"] = "newPasswordRequired";
          delete userAttributes.email_verified;
          delete userAttributes.phone_number_verified;
          cognitoUser.completeNewPasswordChallenge('newPasswordHmkv', userAttributes, this);
        }
      });
    });
  }
  catch(e)
  {
    console.error(e);
  }
  return returnData;
}

Log output

// Put your logs below this line


aws-exports.js

No response

Manual configuration

No response

Additional configuration

{
    "UserPool": {
        "Id": "ap-northeast-1_XXXXXXXXX",
        "Name": "XXXXXXXXXXX",
        "Policies": {
            "PasswordPolicy": {
                "MinimumLength": 8,
                "RequireUppercase": true,
                "RequireLowercase": true,
                "RequireNumbers": true,
                "RequireSymbols": false,
                "TemporaryPasswordValidityDays": 7
            }
        },
        "DeletionProtection": "ACTIVE",
        "LambdaConfig": {},
        "LastModifiedDate": "2025-02-10T15:32:40.535000+09:00",
        "CreationDate": "2025-02-10T14:45:58.915000+09:00",
        "SchemaAttributes": [
            {
                "Name": "profile",
                "AttributeDataType": "String",
                "DeveloperOnlyAttribute": false,
                "Mutable": true,
                "Required": false,
                "StringAttributeConstraints": {
                    "MinLength": "0",
                    "MaxLength": "2048"
                }
            },
            {
                "Name": "address",
                "AttributeDataType": "String",
                "DeveloperOnlyAttribute": false,
                "Mutable": true,
                "Required": false,
                "StringAttributeConstraints": {
                    "MinLength": "0",
                    "MaxLength": "2048"
                }
            },
            {
                "Name": "birthdate",
                "AttributeDataType": "String",
                "DeveloperOnlyAttribute": false,
                "Mutable": true,
                "Required": false,
                "StringAttributeConstraints": {
                    "MinLength": "10",
                    "MaxLength": "10"
                }
            },
            {
                "Name": "gender",
                "AttributeDataType": "String",
                "DeveloperOnlyAttribute": false,
                "Mutable": true,
                "Required": false,
                "StringAttributeConstraints": {
                    "MinLength": "0",
                    "MaxLength": "2048"
                }
            },
            {
                "Name": "preferred_username",
                "AttributeDataType": "String",
                "DeveloperOnlyAttribute": false,
                "Mutable": true,
                "Required": false,
                "StringAttributeConstraints": {
                    "MinLength": "0",
                    "MaxLength": "2048"
                }
            },
            {
                "Name": "updated_at",
                "AttributeDataType": "Number",
                "DeveloperOnlyAttribute": false,
                "Mutable": true,
                "Required": false,
                "NumberAttributeConstraints": {
                    "MinValue": "0"
                }
            },
            {
                "Name": "website",
                "AttributeDataType": "String",
                "DeveloperOnlyAttribute": false,
                "Mutable": true,
                "Required": false,
                "StringAttributeConstraints": {
                    "MinLength": "0",
                    "MaxLength": "2048"
                }
            },
            {
                "Name": "picture",
                "AttributeDataType": "String",
                "DeveloperOnlyAttribute": false,
                "Mutable": true,
                "Required": false,
                "StringAttributeConstraints": {
                    "MinLength": "0",
                    "MaxLength": "2048"
                }
            },
            {
                "Name": "identities",
                "AttributeDataType": "String",
                "DeveloperOnlyAttribute": false,
                "Mutable": true,
                "Required": false,
                "StringAttributeConstraints": {}
            },
            {
                "Name": "sub",
                "AttributeDataType": "String",
                "DeveloperOnlyAttribute": false,
                "Mutable": false,
                "Required": true,
                "StringAttributeConstraints": {
                    "MinLength": "1",
                    "MaxLength": "2048"
                }
            },
            {
                "Name": "phone_number",
                "AttributeDataType": "String",
                "DeveloperOnlyAttribute": false,
                "Mutable": true,
                "Required": false,
                "StringAttributeConstraints": {
                    "MinLength": "0",
                    "MaxLength": "2048"
                }
            },
            {
                "Name": "phone_number_verified",
                "AttributeDataType": "Boolean",
                "DeveloperOnlyAttribute": false,
                "Mutable": true,
                "Required": false
            },
            {
                "Name": "zoneinfo",
                "AttributeDataType": "String",
                "DeveloperOnlyAttribute": false,
                "Mutable": true,
                "Required": false,
                "StringAttributeConstraints": {
                    "MinLength": "0",
                    "MaxLength": "2048"
                }
            },
            {
                "Name": "locale",
                "AttributeDataType": "String",
                "DeveloperOnlyAttribute": false,
                "Mutable": true,
                "Required": false,
                "StringAttributeConstraints": {
                    "MinLength": "0",
                    "MaxLength": "2048"
                }
            },
            {
                "Name": "email",
                "AttributeDataType": "String",
                "DeveloperOnlyAttribute": false,
                "Mutable": true,
                "Required": true,
                "StringAttributeConstraints": {
                    "MinLength": "0",
                    "MaxLength": "2048"
                }
            },
            {
                "Name": "email_verified",
                "AttributeDataType": "Boolean",
                "DeveloperOnlyAttribute": false,
                "Mutable": true,
                "Required": false
            },
            {
                "Name": "given_name",
                "AttributeDataType": "String",
                "DeveloperOnlyAttribute": false,
                "Mutable": true,
                "Required": false,
                "StringAttributeConstraints": {
                    "MinLength": "0",
                    "MaxLength": "2048"
                }
            },
            {
                "Name": "family_name",
                "AttributeDataType": "String",
                "DeveloperOnlyAttribute": false,
                "Mutable": true,
                "Required": false,
                "StringAttributeConstraints": {
                    "MinLength": "0",
                    "MaxLength": "2048"
                }
            },
            {
                "Name": "middle_name",
                "AttributeDataType": "String",
                "DeveloperOnlyAttribute": false,
                "Mutable": true,
                "Required": false,
                "StringAttributeConstraints": {
                    "MinLength": "0",
                    "MaxLength": "2048"
                }
            },
            {
                "Name": "name",
                "AttributeDataType": "String",
                "DeveloperOnlyAttribute": false,
                "Mutable": true,
                "Required": false,
                "StringAttributeConstraints": {
                    "MinLength": "0",
                    "MaxLength": "2048"
                }
            },
            {
                "Name": "nickname",
                "AttributeDataType": "String",
                "DeveloperOnlyAttribute": false,
                "Mutable": true,
                "Required": false,
                "StringAttributeConstraints": {
                    "MinLength": "0",
                    "MaxLength": "2048"
                }
            }
        ],
        "AutoVerifiedAttributes": [
            "email"
        ],
        "UsernameAttributes": [
            "email"
        ],
        "VerificationMessageTemplate": {
            "DefaultEmailOption": "CONFIRM_WITH_CODE"
        },
        "UserAttributeUpdateSettings": {
            "AttributesRequireVerificationBeforeUpdate": []
        },
        "MfaConfiguration": "ON",
        "EstimatedNumberOfUsers": 1,
        "EmailConfiguration": {
            "SourceArn": "arn:aws:ses:ap-northeast-1:000000000000:identity/[email protected]",
            "EmailSendingAccount": "DEVELOPER",
            "ConfigurationSet": "my-first-configuration-set"
        },
        "UserPoolTags": {},
        "Domain": "ap-northeast-XXXXXXXXXX",
        "AdminCreateUserConfig": {
            "AllowAdminCreateUserOnly": true,
            "UnusedAccountValidityDays": 7
        },
        "UsernameConfiguration": {
            "CaseSensitive": false
        },
        "Arn": "arn:aws:cognito-idp:ap-northeast-1:000000000000:userpool/ap-northeast-1_XXXXXXXXX",
        "AccountRecoverySetting": {
            "RecoveryMechanisms": [
                {
                    "Priority": 1,
                    "Name": "verified_email"
                },
                {
                    "Priority": 2,
                    "Name": "verified_phone_number"
                }
            ]
        }
    }
}

Mobile Device

No response

Mobile Operating System

No response

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

No response

@github-actions github-actions bot added pending-triage Issue is pending triage pending-maintainer-response Issue is pending a response from the Amplify team. labels Feb 10, 2025
@KawashimaRyutaro
Copy link
Author

When I set breakpoint to authenticateUserInternal.
The value of challengeName was EMAIL_OTP.

Image

@HuiSF HuiSF added the Auth Related to Auth components/category label Feb 10, 2025
@HuiSF
Copy link
Member

HuiSF commented Feb 10, 2025

Hi @KawashimaRyutaro Thanks for opening this issue. Looking at your dependencies, you are using [email protected]. This package is a legacy package which doesn't work with Amplify JS v6, and it doesn't support Email MFA feature either.

Please use aws-amplify package to use Email MFA feature. See this documentation for more details.

@HuiSF HuiSF added the question General question label Feb 10, 2025
@github-actions github-actions bot removed pending-maintainer-response Issue is pending a response from the Amplify team. pending-triage Issue is pending triage labels Feb 10, 2025
@KawashimaRyutaro
Copy link
Author

@HuiSF
I understand the provided response.
When I use aws-amplify and @aws-amplify/auth,I can authorization with no Error.
Thank you for the clarification and guidance on using the proper package to enable the Email MFA feature.

@github-actions github-actions bot added the pending-maintainer-response Issue is pending a response from the Amplify team. label Feb 11, 2025
@ashwinkumar6
Copy link
Member

Hi @KawashimaRyutaro, thanks for the conformation

We recommend consuming the Auth API via aws-amplify/auth instead of using the scoped packages directly @aws-amplify/auth (doc reference)

Please feel free to let us know if you're facing other issues

@github-actions github-actions bot removed the pending-maintainer-response Issue is pending a response from the Amplify team. label Feb 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auth Related to Auth components/category question General question
Projects
None yet
Development

No branches or pull requests

3 participants