amplify-js: V6 upgrade causes AuthUserPoolException

Before opening, please confirm:

JavaScript Framework

Angular

Amplify APIs

Authentication

Amplify Categories

auth

Environment information

System:
    OS: macOS 14.1.1
    CPU: (8) arm64 Apple M1 Pro
    Memory: 46.44 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.18.2 - ~/.nvm/versions/node/v18.18.2/bin/node
    npm: 9.8.1 - ~/.nvm/versions/node/v18.18.2/bin/npm
  Browsers:
    Chrome: 119.0.6045.159
    Edge: 119.0.2151.72
    Safari: 17.1
  npmPackages:
    @angular-devkit/build-angular: ^16.2.8 => 16.2.8
    @angular/animations: ^16.2.11 => 16.2.11
    @angular/cdk: ^16.2.10 => 16.2.10
    @angular/cli: ^16.2.8 => 16.2.8
    @angular/common: ^16.2.11 => 16.2.11
    @angular/compiler: ^16.2.11 => 16.2.11
    @angular/compiler-cli: ^16.2.11 => 16.2.11
    @angular/core: ^16.2.11 => 16.2.11
    @angular/forms: ^16.2.11 => 16.2.11
    @angular/localize: ^16.2.11 => 16.2.11
    @angular/platform-browser: ^16.2.11 => 16.2.11
    @angular/platform-browser-dynamic: ^16.2.11 => 16.2.11
    @angular/router: ^16.2.11 => 16.2.11
    @auth0/angular-jwt: ^5.2.0 => 5.2.0
    @aws-amplify/auth: ^6.0.5 => 6.0.5
    @aws-amplify/auth/cognito:  undefined ()
    @aws-amplify/auth/cognito/server:  undefined ()
    @aws-amplify/auth/server:  undefined ()
    @cypress/angular:  0.0.0-development
    @cypress/mount-utils:  0.0.0-development
    @cypress/react:  0.0.0-development
    @cypress/react18:  0.0.0-development
    @cypress/schematic: ^2.5.1 => 2.5.1
    @cypress/svelte:  0.0.0-development
    @cypress/vue:  0.0.0-development
    @cypress/vue2:  0.0.0-development
    @fortawesome/angular-fontawesome: ^0.13.0 => 0.13.0
    @fortawesome/fontawesome-free: ^6.4.2 => 6.4.2
    @fortawesome/fontawesome-svg-core: ^6.4.2 => 6.4.2
    @fortawesome/free-brands-svg-icons: ^6.4.2 => 6.4.2
    @fortawesome/free-regular-svg-icons: ^6.4.2 => 6.4.2
    @fortawesome/free-solid-svg-icons: ^6.4.2 => 6.4.2
    @ng-bootstrap/ng-bootstrap: ^15.1.2 => 15.1.2
    @ngrx/effects: ^16.3.0 => 16.3.0
    @ngrx/entity: ^16.3.0 => 16.3.0
    @ngrx/router-store: ^16.3.0 => 16.3.0
    @ngrx/store: ^16.3.0 => 16.3.0
    @ngrx/store-devtools: ^16.3.0 => 16.3.0
    @types/bootstrap: ^5.2.8 => 5.2.8
    @types/canvas-confetti: ^1.4.3 => 1.6.0
    @types/jasmine: ~3.8.0 => 3.8.2
    @types/lodash: ^4.14.182 => 4.14.192
    @types/node: ^12.11.1 => 12.20.55 (20.3.1, 16.18.40)
    @types/segment-analytics: ^0.0.34 => 0.0.34
    @types/textarea-caret: ^3.0.3 => 3.0.3
    @typescript-eslint/eslint-plugin: ^5.40.1 => 5.57.0
    @typescript-eslint/parser: ^5.40.1 => 5.57.0
    bootstrap: ^5.3.2 => 5.3.2
    bootstrap-icons: ^1.11.1 => 1.11.1
    canvas-confetti: ^1.9.0 => 1.9.0
    chart.js: ^4.4.0 => 4.4.0
    chart.js-auto:  undefined ()
    chart.js-helpers:  undefined ()
    cypress: ^13.1.0 => 13.1.0
    cypress-localstorage-commands: ^2.2.1 => 2.2.4
    eslint: ^8.0.0 => 8.37.0
    eslint-config-prettier: ^8.5.0 => 8.8.0
    eslint-plugin-html: ^7.1.0 => 7.1.0
    eslint-plugin-tsdoc: ^0.2.14 => 0.2.17
    gmail-tester: ^1.3.8 => 1.3.8
    jasmine-core: ~3.8.0 => 3.8.0
    karma: ~6.3.0 => 6.3.20
    karma-chrome-launcher: ~3.1.0 => 3.1.1
    karma-coverage: ~2.0.3 => 2.0.3
    karma-coverage-coffee-example:  1.0.0
    karma-jasmine: ~4.0.0 => 4.0.2
    karma-jasmine-html-reporter: ~1.7.0 => 1.7.0
    karma-spec-reporter: ^0.0.36 => 0.0.36
    karma-verbose-reporter: 0.0.8 => 0.0.8
    lodash: ^4.17.21 => 4.17.21
    ng-circle-progress: ^1.7.1 => 1.7.1
    ng2-charts: ^5.0.3 => 5.0.3
    ng2-charts-schematics:  0.0.1
    ngx-cookie-service: ^16.0.1 => 16.0.1
    ngx-webstorage-service: ^5.0.0 => 5.0.0
    patternomaly: ^1.3.2 => 1.3.2
    prettier: 2.8.0 => 2.8.0
    replace-in-file: ^6.2.0 => 6.3.5
    rxjs: ^7.5.6 => 7.8.1 (6.6.7)
    rxjs/ajax:  undefined ()
    rxjs/fetch:  undefined ()
    rxjs/internal-compatibility:  undefined ()
    rxjs/operators:  undefined ()
    rxjs/testing:  undefined ()
    rxjs/webSocket:  undefined ()
    textarea-caret: ^3.1.0 => 3.1.0
    tslib: ^2.6.2 => 2.6.2 (2.6.1, 1.14.1)
    typescript: ~5.1.3 => 5.1.3
    zone.js: ~0.13.3 => 0.13.3
  npmGlobalPackages:
    @aws-amplify/cli: 12.8.2
    corepack: 0.19.0
    npm: 9.8.1

Describe the bug

After upgrading to aws-amplify/auth v6 I’m unable to login, due to the UserPool configuration:

Captura de pantalla 2023-11-24 a las 13 14 27

I’m able to start the login flow (user selection, credentials form, etc.) but when relocation happens to /reloc?code=… in my homepage, then it fails. That means the user pool is properly setup from my login page (if not, I couldn’t authenticate at all. My login page is running Amplify.configure successfully)

  • I already migrated the Auth.configure to Amplify.configure
  • I already migrated my code from Auth.signIn to signInWithRedirect

It seems like part of the Amplify framework is not initialized. The exception is provoked by someone who is calling to this assertion function with an empty cognitoConfig (In my config JSON passed to Amplify.configure I do have values for userPoolId and userPoolClientId):

function assertTokenProviderConfig(cognitoConfig) {
    let assertionValid = true; // assume valid until otherwise proveed
    if (!cognitoConfig) {
        assertionValid = false;
    }
    else {
        assertionValid =
            !!cognitoConfig.userPoolId && !!cognitoConfig.userPoolClientId;
    }
    return (0, errorHelpers_1.assert)(assertionValid, errorHelpers_1.AuthConfigurationErrorCode.AuthUserPoolException);
}

Expected behavior

Successful login

Reproduction steps

  1. Project is configured with @aws-amplify/auth v5.6.5
  2. Update @aws-amplify/auth lib to v6.0.5
  3. Migrate the code according to the ‘POOR’ documentation in https://docs.amplify.aws/angular/build-a-backend/troubleshooting/migrate-from-javascript-v5-to-v6/

Code Snippet

This is my configure call passing the JSON with the user pool:

Amplify.configure(config);

These are my functions to login (google/microsoft):

googleSocialSignIn(): Promise<void> {
  return signInWithRedirect({
    provider: 'Google',
  });
}

officeSocialSignIn(): Promise<void> {
  return signInWithRedirect({
    provider: { custom: 'Office' },
  });
}

Log output

[DEBUG] 32:37.597 Hub - Dispatching to core with  {event: 'configure', data: {aws_cognito_region: ...}}
config.service.ts:51 ERROR Error: Uncaught (in promise): AuthUserPoolException: Auth UserPool not configured.
AuthUserPoolException: Auth UserPool not configured.
    at createAssertionFunction.mjs:8:15
    at assertTokenProviderConfig (index.mjs:17:18)
    at TokenStore.mjs:123:34
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (asyncToGenerator.js:3:1)
    at _next (asyncToGenerator.js:22:1)
    at asyncToGenerator.js:27:1
    at new ZoneAwarePromise (zone.js:1411:21)
    at asyncToGenerator.js:19:1
    at DefaultTokenStore.getAuthKeys (TokenStore.mjs:125:115)
    at resolvePromise (zone.js:1193:31)
    at zone.js:1100:17
    at zone.js:1116:33
    at asyncGeneratorStep (asyncToGenerator.js:6:1)
    at _throw (asyncToGenerator.js:25:1)
    at _ZoneDelegate.invoke (zone.js:368:26)
    at Object.onInvoke (core.mjs:11083:33)
    at _ZoneDelegate.invoke (zone.js:367:52)
    at Zone.run (zone.js:129:43)
    at zone.js:1257:36

aws-exports.js

No response

Manual configuration

{
   "aws_cognito_region":"MY-REGION",
   "aws_project_region":"MY-REGION",
   "aws_user_pools_id":"MY-USER-POOLS-ID",
   "aws_user_pools_web_client_id":"MY-USER-POOLS-CLIENT-ID",
   "federationTarget":"COGNITO_USER_POOLS",
   "oauth":{
      "domain":"MY-DOMAIN",
      "redirectSignIn":"MY-HOST/redirect/",
      "redirectSignOut":"MY-HOST/logout/",
      "responseType":"code",
      "scope":[
         "email",
         "openid",
         "profile"
      ]
   }
}

Also tried passing the new model (even though the legacy one above should be converted by the library and works properly)

Amplify.configure({
  Auth: {
    Cognito: {
      userPoolId: config.aws_user_pools_id,
      userPoolClientId: config.aws_user_pools_web_client_id,
      loginWith: {
        oauth: {
          domain: config.oauth.domain,
          scopes: config.oauth.scope,
          redirectSignIn: config.oauth.redirectSignIn,
          redirectSignOut: config.oauth.redirectSignOut,
          responseType: config.oauth.responseType,
        },
      },
    },
  },
});

Additional configuration

No response

Mobile Device

No response

Mobile Operating System

No response

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

Perhaps the ‘configure’ call is not fully configuring the Amplify framework. Notice how the DEBUG output is much more complete in v5 in the login page. This is before I try to login, so before I get the UserPool exception or any other error in the browser console.

  • Login page. DEBUG output in v5.6.5:
[webpack-dev-server] Server started: Hot Module Replacement disabled, Live Reloading enabled, Progress disabled, Overlay enabled.
vendor.js:19 [DEBUG] 13:14.753 Amplify - component registered in amplify CredentialsClass {_gettingCredPromise: null, _refreshHandlers: {…}, Auth: undefined}
url-template.ts:22 [DEBUG] 13:14.769 Amplify - component registered in amplify AuthClass {userPool: null, user: null, oAuthFlowInProgress: false, autoSignInInitiated: false, inflightSessionPromise: null, …}
url-template.ts:22 [DEBUG] 13:14.769 AuthClass - configure Auth
url-template.ts:22 [DEBUG] 13:14.769 Parser - parse config (3) [{…}, 'to amplifyconfig', {…}]
url-template.ts:22 [DEBUG] 13:14.770 Hub - Dispatching to auth with  {event: 'configured', data: null, message: 'The Auth category has been configured successfully'}
app.module.ts:101 Initializing App - DEV
config.service.ts:49 [DEBUG] 13:14.910 AuthClass - configure Auth
config.service.ts:49 [DEBUG] 13:14.911 Parser - parse config (3) [{…}, 'to amplifyconfig', {…}]
config.service.ts:49 [DEBUG] 13:14.911 Hub - Dispatching to auth with  {event: 'parsingCallbackUrl', data: {…}, message: 'The callback url is being parsed'}
config.service.ts:49 [DEBUG] 13:14.912 Hub - Dispatching to auth with  {event: 'parsingCallbackUrl', data: {…}, message: 'The callback url is being parsed'}
config.service.ts:49 [DEBUG] 13:14.912 Hub - Dispatching to auth with  {event: 'configured', data: null, message: 'The Auth category has been configured successfully'}
config.service.ts:49 [DEBUG] 13:14.912 Hub - Dispatching to auth with  {event: 'configured', data: null, message: 'The Auth category has been configured successfully'}
core.mjs:26656 Angular is running in development mode.
login.component.ts:93 [DEBUG] 13:14.954 AuthClass - getting current authenticated user
ConsoleLogger.js:122 [DEBUG] 13:14.956 AuthClass - get current authenticated userpool user
ConsoleLogger.js:122 [DEBUG] 13:14.956 AuthClass - Failed to get user from user pool
ConsoleLogger.js:134 [DEBUG] 13:14.956 AuthClass - The user is not authenticated by the error No current user
  • Login page. DEBUG output in v6.0.5:
[webpack-dev-server] Server started: Hot Module Replacement disabled, Live Reloading enabled, Progress disabled, Overlay enabled.
app.module.ts:101 Initializing App - DEV
config.service.ts:51 [DEBUG] 23:40.685 Hub - Dispatching to core with  {event: 'configure', data: {…}}
core.mjs:26656 Angular is running in development mode.

About this issue

  • Original URL
  • State: closed
  • Created 7 months ago
  • Comments: 47 (9 by maintainers)

Most upvoted comments

@pablovargasosorio can you confirm that you installed @aws-amplify/auth into your project? If so the recommendation is to install aws-amplify package instead and import from it. @aws-amplify/auth is marked for internal use only.

For example

import { Amplify } from 'aws-amplify'
import { signInWithRedirect } from 'aws-amplify/auth' // not '@aws-amplify/auth'
import { Hub } from 'aws-amplify/utils'

I got it working with a hybrid:

    Auth: {
        identityPoolId: config.cognito.IDENTITY_POOL_ID,
        region: config.cognito.REGION,
        userPoolWebClientId: config.cognito.APP_CLIENT_ID,
        mandatorySignIn: false,
        Cognito: {
            userPoolId: config.cognito.USER_POOL_ID,
            userPoolClientId: config.cognito.APP_CLIENT_ID
        }...

I used documentation from the API section blended with the Auth section. All of the Auth options should be under the Auth section in the documentation. And more formally documented with all potential options than just an example.

@natuan62 For me I had to use Amplify.configure() in both a server component and a client component. I’m using Next.js so I put it into my Amplify context file in the initialization process.

Just adding this for reference if others see this because seems like a lot of activity on the thread, This is not related to the config questions, but if you have the problem AuthUserPoolException: Auth UserPool not configured.

If you were using @aws-amplify dependencies before, use the aws-amplify single import instead for 6.0.2+

BEFORE Screenshot 2023-12-14 at 5 51 26 PM

AFTER Screenshot 2023-12-14 at 5 52 49 PM

@nadetastic to clarify, things are a bit unclear. A few points:

  1. Inconsistent levels of userPoolClientId and userPoolId configuration. Here and here in the documentation the userPool config is two levels down under “Auth” -> “Cognito”. But here it is only one level down, directly under “Auth”. Which is it? It would help to correct it in all places to what it should be.
  2. The identity pool config (identityPoolId) is under the top-level “Auth” configuration only. The only place I can see it demonstrated is here that I stumbled upon. And, this identity pool ID is a Cognito identity pool, or regardless if it is a third party identity pool (e.g. Facebook, Google), it is still defined and ID’d through Cognito. Therefore, one could argue it too should be down one level in the “Cognito” JSON config.
  3. Not to nitpick, but a suggestion is the definitions of these config elements should be in a formal online document/or dictionary, preferably not scattered through examples. A centralized, ‘API manual’. If there is one somewhere I could not find it, perhaps my mistake. But a formal, central, document reference of every possible configuration element, description, defaults, parameter inputs, options, mins/maxes, possible exceptions, etc.

Thanks for checking and helping improve things.

I still have this issue and cannot figure out how to fix it… using "aws-amplify": "^6.0.28" no matter how I get the Auth not configured error 😦

In my case, the version inconsistency prevented the signOut from working.

  "dependencies": {
    "@aws-amplify/auth": "^6.0.13",
    "@aws-amplify/core": "^6.0.13",
-   "aws-amplify": "^6.0.10"
+   "aws-amplify": "^6.0.13"
  }

Upgrading “aws-amplify” fixed the problem.

Getting same error on "aws-amplify": "^6.0.6"

Amplify.configure({
    Auth: {
            mandatorySignIn: false,
            region: config.cognito.REGION,
            userPoolId: config.cognito.USER_POOL_ID,
            identityPoolId: config.cognito.IDENTITY_POOL_ID,
            userPoolWebClientId: config.cognito.APP_CLIENT_ID
    },
    API: {...

I have reviewed all of the documentation and migration guide and nothing seems out of whack. Help please…

@pablovargasosorio can you confirm that you installed @aws-amplify/auth into your project? If so the recommendation is to install aws-amplify package instead and import from it. @aws-amplify/auth is marked for internal use only.

For example

import { Amplify } from 'aws-amplify'
import { signInWithRedirect } from 'aws-amplify/auth' // not '@aws-amplify/auth'
import { Hub } from 'aws-amplify/utils'

@nadetastic That was the reason of the issue. I changed my package.json

FROM:

"@aws-amplify/auth": "6.0.2"

TO:

"aws-amplify": "6.0.2",

Also changed my imports to use from ‘aws-amplify/auth’, instead of ‘@aws-amplify/auth’ and login works Thank you very much!

I strongly recommend to improve the changelog documentation to let us know the ‘@’ notation is deprecated in V6… Thanks again!

@jgabriel98 I found the cause of my issue. You should be sure 100% you configure amplify - eventually I did it a couple of times - before calling the API (even only to test it, try to call it just before the get or post or whatever call). Just a suggestion, with the other version of amplify same code it wasn’t necessary!

For those still struggling here, it took me a while but I was able to get everything working. I put together a simple demo stripped from my production app. The demo is not functional but it shows the exact amplify configuration, locked package versions for amplify and nextjs as well as both server and client Amplify.configure implementations. If it is not clear or if it would be beneficial for me to complete the demo to make it run, please lmk.

https://github.com/btg5679/amplify6-auth-nextjs-demo

I can confirm this 👍 After removing our used category @aws-amplify/auth and only using aws-amplify it worked for me. They also described the “old” @aws-amplify/auth package as INTERNAL USE ONLY: https://www.npmjs.com/package/@aws-amplify/auth

So, since v6 you need to install the whole “aws-amplify” package. But you can still import from “aws-amplify/auth”

I have done that but am still having the same issue

I’m still having he same issue after trying everything else mentioned in this thread and anywhere else. It is a vue/vite app with pnpm. package.json

	"dependencies": {
		"aws-amplify": "6.0.9",
		"@aws-amplify/pubsub": "6.0.9",
...

main.ts

import type { ResourcesConfig } from "aws-amplify";
import { Amplify } from "aws-amplify";
import { getCurrentUser } from "aws-amplify/auth";

const config: ResourcesConfig = {
	Auth: {
		Cognito: {
			// REQUIRED - Amazon Cognito Identity Pool ID
			identityPoolId: "___",
			// OPTIONAL - Amazon Cognito User Pool ID
			userPoolId: "___",
			// OPTIONAL - Amazon Cognito Web Client ID (26-char alphanumeric string)
			userPoolClientId: "___",
		},
	},
};
Amplify.configure(awsExports);
console.log(Amplify.getConfig());
const authUser = await getCurrentUser(); // This is the line that causes the error

It console logs the proper config then throws an error when calling the getCurrentUser function. Looking in the debugger it seems like the Amplify class that the function is importing from @aws-amplify/core is not the same instance as the one I import from aws-amplify. image

@willjstevens thanks for the feedback and context! Let me clarify a bit:

The first and second links in item 1, is the proper way to set up the resources, however it doesn’t clearly show identityPoolId configuration. The third link in item 1 and first link in item 2(link) is a reference to how config would be done previous versions on amplify (v5 and before, the switch under “Choose your framework/language” on the top left)

I’m working to clarify the documentation in Configure Amplify categories (item 1 links) to clearly show how to configure identityPoolId and a few more options 😃

@willjstevens with amplify 6, some of those things need to go under Auth: { Cognito : {} } instead otop level Auth. I don’t remember which ones but check the spec!

@mnovati Thanks for your reply. I can confirm I have it working. I didn’t have any @amplify references in my package.json file. But I did go ahead and delete my node_modules folder and install amplify 6.0.5. Perhaps @amplify references were still kicking about in my node_modules? @nadetastic thanks for investigating - happy to have this sorted.

Can confirm removing individual @aws-amplify packages for each module and using just ONE package: aws-amplify solves this problem.

HI @nadetastic - I can confirm I’ve just run in to this issue as well. I won’t have time until tomorrow to provide more details, but in case helpful, it’s worth mentioning that it occurred when attempting to configure the cognitoUserPoolsTokenProvider and when I removed any references to it, everything worked as expected.