aws-amplify / amplify-js

A declarative JavaScript library for application development using cloud services.
https://docs.amplify.aws/lib/q/platform/js
Apache License 2.0
9.38k stars 2.1k forks source link

Auth signUp works but signIn Throws AuthUserPoolException #13375

Closed desert-digital closed 1 month ago

desert-digital commented 1 month ago

How did you install the Amplify CLI?

npm

If applicable, what version of Node.js are you using?

20.10.0

Amplify CLI Version

12.12.0

What operating system are you using?

Mac OS Venture 12.7.4

Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.

None

Describe the bug

Recently upgraded from v5 to v6.

A call to signUp results in a new user being created. A call to signIn results in an exception: AuthUserPoolException

Changed the main.ts call to use the amplifyconfiguration.json file.

import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { AppModule } from './app/app.module';
import { environment } from './environments/environment';

import { Amplify } from '@aws-amplify/core';

import amplifyconfig from './amplifyconfiguration.json';

Amplify.configure(amplifyconfig);

if (environment.production) {
  enableProdMode();
}

platformBrowserDynamic().bootstrapModule(AppModule)
  .catch(err => console.error(err));

The amplifyconfiguration.json file has the required information (it appears):

{
  "aws_project_region": "us-west-1",
  "aws_cognito_identity_pool_id": "us-west-1:b2d18410-0c7e-412b-a3d6-373ba5bdXXXX",
  "aws_cognito_region": "us-west-1",
  "aws_user_pools_id": "us-west-1_2UPFyXXXX",
  "aws_user_pools_web_client_id": "4k14sf2jo3n8sd5p3erv1eXXXX",
  "oauth": {},
  "aws_cognito_username_attributes": [],
  "aws_cognito_social_providers": [],
  "aws_cognito_signup_attributes": [
    "EMAIL"
  ],
  "aws_cognito_mfa_configuration": "OFF",
  "aws_cognito_mfa_types": [
    "SMS"
  ],
  "aws_cognito_password_protection_settings": {
    "passwordPolicyMinLength": 8,
    "passwordPolicyCharacters": []
  },
  "aws_cognito_verification_mechanisms": [
    "EMAIL"
  ],
  "aws_appsync_graphqlEndpoint": "https://vltdbltmvrhxbh62dzitk76nq4.appsync-api.us-west-1.amazonaws.com/graphql",
  "aws_appsync_region": "us-west-1",
  "aws_appsync_authenticationType": "AMAZON_COGNITO_USER_POOLS",
  "aws_appsync_apiKey": "da2-ueamwb5nsrgl7jlruilhjpXXXX"
}

Expected behavior

call to signIn with a user should result in successful login

Reproduction steps

Please see above.

Call to signUp:

  async onRegisterPressed() {

    try {
      await signUp({
        username: this.signupForm.value.userName,
        password: this.signupForm.value.password,
        options: {
          userAttributes: {
            email: this.signupForm.value.email,
            phone_number: this.signupForm.value.phoneNumber
          }
        }
      }).then(() => {
        this.signingUp = false;
        console.log('Changed signingUp');
        this.verifyForm.patchValue({
          userNameWithCode: this.signupForm.value.userName
        });
        this._snackBar.open('Check your email for a verification code', 'OK', { duration: 5000 });
      }).catch(error => {
        this._snackBar.open(error.message, 'OK', { duration: 10000 })
      });
    }
    catch (error) {
      this._snackBar.open(error.message, 'OK', { duration: 10000 })
    }
  }

Call to signIn:

  async onLogin() {
    try {
      await signIn({ username: this.userName, password: this.password });
      this.router.navigate(['login/loading']);
    } catch (error) {
      if (error.code === 'UserNotFoundException') {
        this._snackBar.open('User Not Found', 'OK', { duration: 3000 });
      }
      else if (error.code === 'NotAuthorizedException') {
        this._snackBar.open('Wrong Password', 'OK', { duration: 3000 });
      }
      else {
        console.log(JSON.stringify(error))
        this._snackBar.open('A Signin Error Occurred, please try again', 'OK', { duration: 3000 });
      }
    }
  }

Project Identifier

b4b01341933ab2fb102d890fe649cf95

Log output

``` # Put your logs below this line ```

Additional information

None

Before submitting, please confirm:

ykethan commented 1 month ago

hey,👋 thanks for raising this! I'm going to transfer this over to our JS repository for better assistance 🙂

cwomack commented 1 month ago

Hello, @desert-digital 👋. Are you able to share what's in your package.json file so we can see your dependencies? Also, it looks like you're using an improper import for v6. Can you change your import for Amplify to be the following:

import { Amplify } from 'aws-amplify';

Instead of:

import { Amplify } from '@aws-amplify/core';

There's potentially more updates you'll want to consider that are detailed in the migration guide for Auth as well. Let us know if making these changes helps resolve any issues!

desert-digital commented 1 month ago

Hi Chris:

Thanks for the quick reply. That did the trick. I'm not sure where I picked up that syntax, but I'm glad I included it!

cwomack commented 1 month ago

Glad to hear it, @desert-digital! If you have any other blockers, feel free to open a new issue. I'll close the issue out as resolved then.