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

V6 upgrade causes AuthUserPoolException #12627

Closed
3 tasks done
pablovargasosorio opened this issue Nov 24, 2023 · 52 comments
Closed
3 tasks done

V6 upgrade causes AuthUserPoolException #12627

pablovargasosorio opened this issue Nov 24, 2023 · 52 comments
Assignees
Labels
Auth Related to Auth components/category documentation Related to documentation feature requests pending-response Issue is pending response from the issue requestor question General question

Comments

@pablovargasosorio
Copy link

pablovargasosorio commented Nov 24, 2023

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.
@pablovargasosorio pablovargasosorio added the pending-triage Issue is pending triage label Nov 24, 2023
@nadetastic nadetastic added the Auth Related to Auth components/category label Nov 24, 2023
@rkstgr
Copy link

rkstgr commented Nov 27, 2023

Downgrade @aws-amplify/auth and @aws-amplify/core to 6.0.2

I had the same problem when I upgraded @aws-amplify/auth from v6.0.2 to v6.0.5. It worked again when I downgraded to v6.0.2, but I had to downgrade @aws-amplify/core as well.

@pablovargasosorio
Copy link
Author

Unfortunately v6.0.2 is not working to me neither :(

@rkstgr
Copy link

rkstgr commented Nov 27, 2023

Have you downgraded both dependencies?

@pablovargasosorio
Copy link
Author

Yeah, and I made sure that's the version installed in both auth/core, no luck, same error...

@nadetastic nadetastic self-assigned this Nov 27, 2023
@nadetastic
Copy link
Contributor

Hi @pablovargasosorio thanks for opening this issue. Quick question, are you calling signInWithRedirect() on the same path as your redirectSignIn? If not can you try importing signInWIthRedirect on the same path?

@nadetastic nadetastic added pending-response Issue is pending response from the issue requestor and removed pending-triage Issue is pending triage labels Nov 27, 2023
@dkhuntrods
Copy link

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.

@nadetastic
Copy link
Contributor

@dkhuntrods thank you for the context, can you share the code of how you have implemented your TokenProvider?

@pablovargasosorio
Copy link
Author

Hi @pablovargasosorio thanks for opening this issue. Quick question, are you calling signInWithRedirect() on the same path as your redirectSignIn? If not can you try importing signInWIthRedirect on the same path?

@nadetastic The reloc path is a 'virtual' route with no components, but I tried to just importing the sign-in method in the same place I do the Amplify.configure, but I it doesn't fix it.
Captura de pantalla 2023-11-28 a las 9 31 05

@nadetastic nadetastic added investigating This issue is being investigated and removed pending-response Issue is pending response from the issue requestor labels Nov 28, 2023
@nadetastic
Copy link
Contributor

nadetastic commented Nov 28, 2023

@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 nadetastic added pending-response Issue is pending response from the issue requestor and removed investigating This issue is being investigated labels Nov 28, 2023
@pringtest
Copy link

For me this error happen during signOut. So I just downgrade to "aws-amplify": "^6.0.2" as mention by @rkstgr.

In the code I import like this as mention by @nadetastic

import { Hub } from 'aws-amplify/utils';
import { signOut, fetchAuthSession } from 'aws-amplify/auth';

Now it working.

Thank @rkstgr @nadetastic.

@pablovargasosorio
Copy link
Author

pablovargasosorio commented Nov 29, 2023

@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!

@nadetastic
Copy link
Contributor

Glad to have gotten your issues resolved!

@pablovargasosorio thank you for the feedback! We are working to make improvements in the migration guide 🙂

@InspiredJason
Copy link

InspiredJason commented Nov 30, 2023

@nadetastic I'm having a similar problem. I'm on version 6.0.2 defined in my package.json as "aws-amplify": "6.0.2". The configure method runs, but when I attempt to sign in, I get this error: error signing in AuthUserPoolException: Auth UserPool not configured. I have checked the userPoolId, userClientPoolId and identityPoolId, which all exist in Cognito.

The error seems be happening when calling Amplify.getConfig() in the signInWithSRP function. authConfig is undefined.

Here's my stack trace and code below. Is there something I'm missing?

error signing in AuthUserPoolException: Auth UserPool not configured.
    at http://localhost:3000/@fs/Users/jdog/Projects/The%20Gap%20App/node_modules/.vite/deps/chunk-PE4GYZUI.js?v=fdd028b4:201:11
    at assertTokenProviderConfig (http://localhost:3000/@fs/Users/jdog/Projects/The%20Gap%20App/node_modules/.vite/deps/chunk-PE4GYZUI.js?v=fdd028b4:404:10)
    at signInWithSRP (http://localhost:3000/@fs/Users/jdog/Projects/The%20Gap%20App/node_modules/.vite/deps/chunk-BG77EEEK.js?v=fdd028b4:6163:3)
    at signIn (http://localhost:3000/@fs/Users/jdog/Projects/The%20Gap%20App/node_modules/.vite/deps/chunk-BG77EEEK.js?v=fdd028b4:6275:14)
    at async signIn (http://localhost:3000/src/auth/sign-in/AuthSignInStore.tsx:34:11)
import { signUp, confirmSignUp, signIn, signOut, getCurrentUser, fetchAuthSession, fetchUserAttributes, fetchMFAPreference } from 'aws-amplify/auth'
import { Amplify } from 'aws-amplify'

export default class AuthStore {
   // ...
   static configure() {
      Amplify.configure({
         Auth: {
            Cognito: {
               userPoolId: variables.userPoolId,
               userPoolClientId: variables.userPoolWebClientId,
               identityPoolId: variables.identityPoolId,
               loginWith: {
                  oauth: {
                     domain: variables.userPoolDomain,
                     scopes: notNull(variables.cognitoOauthScopes) as OAuthScope[],
                     redirectSignIn: [variables.appHost],
                     redirectSignOut: [variables.appHost],
                     responseType: 'code',
                  },
               },
            }
         },
         API: {
            REST: {
               [variables.amplifyApiName]: {
                  endpoint: import.meta.env.VITE_API_URL,
                  region: import.meta.env.VITE_REGION,
               }
            }
         }
      })
   }
   signIn = async () => {
      try {
         const { isSignedIn, nextStep } = await signIn({
            username: this.fields.email,
            password: this.fields.password,
         })

         console.log(isSignedIn, nextStep)

      } catch (error) {
         console.log('error signing in', error)
      }
   }
}

@nadetastic
Copy link
Contributor

Hi @InspiredJason can you provide a bit more context on you app? What framework is it (Angular for ex)? And an example of how you are using the AuthStore.signIn() you have defined above?

@InspiredJason
Copy link

InspiredJason commented Nov 30, 2023

Hi @nadetastic - thanks for the reply. We're using SST as our serverless framework including a React frontend. Below is an extract of the signin component along. Essentially, just a react component, which configures Amplify, then a call to our sign in function shown in my message above in our AuthStore class. I've also included the result of a call to Amplify.getConfig() after calling configure(). Anything stick out to you?

image
import { observer } from 'mobx-react-lite'
import { useAuthStore } from '../AuthStore'
import onEnterProp from 'reusable/utils/on-enter-prop'
import ButtonWithProgress from 'reusable/mui/progress-button/ButtonWithProgress'
import TextFieldPassword from 'reusable/mui/text-field-password/TextFieldPassword'
import Box from '@mui/material/Box'
import useStore from 'reusable/mobx-store-utils'

export default observer(function AuthSignIn() {
   const authStore = useAuthStore()
   const formHandler = authStore.formHandler

   // just a useEffect hook with empty param list
   useInitialMount(() => {
      AuthStore.configure()
   })

   return (
      <>
               <Box>
                  {formHandler.email.bindInput(ip =>
                     <TextField
                        autoFocus
                        fullWidth
                        label="Email"
                        name="email"
                        {...onEnterProp(authStore.signIn)}
                        {...ip}
                     />)}
               </Box>
               <Box>
                  {formHandler.password.bindInput(ip =>
                     <TextFieldPassword
                        name="password"
                        fullWidth
                        label="Password"
                        {...onEnterProp(authStore.signIn)}
                        {...ip}
                     />)}
               </Box>
               <ButtonWithProgress
                  loading={authStore.loader.isLoading}
                  variant="contained"
                  onClick={authStore.signIn}>
                  Sign in
               </ButtonWithProgress>
      </>
   )
})```

               
               

@nadetastic nadetastic added investigating This issue is being investigated and removed pending-response Issue is pending response from the issue requestor labels Dec 4, 2023
@mnovati
Copy link

mnovati commented Dec 4, 2023

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

@InspiredJason
Copy link

@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.

@OperationalFallacy
Copy link

OperationalFallacy commented Dec 7, 2023

I hope I'm on time to the party... it's not working!

Upd: never mind... was trying to call fetchAuthSession() on public page

image

I can't figure out what's causing it, custom and default configs have the same effect. This happens on main public page, there is no authentication.

'use client';
import { Amplify } from 'aws-amplify';
import config from '../../amplifyconfiguration.json';
import { ResourcesConfig } from '@aws-amplify/core';

const [localRedirectSignIn, productionRedirectSignIn] = config.oauth.redirectSignIn.split(',');
const [localRedirectSignOut, productionRedirectSignOut] = config.oauth.redirectSignOut.split(',');

if (typeof window !== 'undefined') {
  const isLocalhost = Boolean(
    window.location.hostname === 'localhost' ||
      // [::1] is the IPv6 localhost address.
      window.location.hostname === '[::1]' ||
      // 127.0.0.1/8 is considered localhost for IPv4.
      window.location.hostname.match(/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/),
  );

  const updatedAwsConfig: ResourcesConfig = {
    ...config,
    Auth: {
      Cognito: {
        userPoolClientId: config.aws_user_pools_id,
        userPoolId: config.aws_user_pools_id,
        loginWith: {
          oauth: {
            ...config.oauth,
            domain: config.oauth.domain,
            scopes: config.oauth.scope,
            responseType: config.oauth.responseType as 'code' | 'token',
            redirectSignIn: [isLocalhost ? localRedirectSignIn : productionRedirectSignIn],
            redirectSignOut: [isLocalhost ? localRedirectSignOut : productionRedirectSignOut],
          },
        },
      },
    },
  };
  Amplify.configure(updatedAwsConfig);
  console.log('Amplify done initial configuration')
}

export default function ConfigureAmplifyClientSide() {
  return null;
}

Deps

    "@aws-amplify/api@6.0.6",
    "@aws-amplify/ui-react@^6.0.4",
    "aws-amplify@6.0.6",
    ```

@nadetastic
Copy link
Contributor

Hi @OperationalFallacy, just to confirm, is this an issue for you?

@willjstevens
Copy link

@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.

@nadetastic
Copy link
Contributor

@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 😃

@btg5679
Copy link

btg5679 commented Dec 15, 2023

The config here is not valid according to the typescript types in 6.0.2

@mnovati
Copy link

mnovati commented Dec 15, 2023

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

@mvejca
Copy link

mvejca commented Dec 28, 2023

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

@natuan62
Copy link

natuan62 commented Jan 7, 2024

I'm still facing with this issue

"aws-amplify": "^6.0.10",

image

err AuthUserPoolException: Auth UserPool not configured.
    at http://localhost:8081/node_modules/.vite/deps/chunk-PZK3XFUA.js?v=5a19cc1b:42:11
    at assertTokenProviderConfig (http://localhost:8081/node_modules/.vite/deps/chunk-PZK3XFUA.js?v=5a19cc1b:164:10)
    at signInWithSRP (http://localhost:8081/node_modules/.vite/deps/chunk-PZK3XFUA.js?v=5a19cc1b:10090:3)
    at signIn (http://localhost:8081/node_modules/.vite/deps/chunk-PZK3XFUA.js?v=5a19cc1b:10203:14)
    at async logIn (http://localhost:8081/src/views/SignIn.vue:53:9)
SignIn.vue: Auth UserPool not configured. err

@natuan62
Copy link

natuan62 commented Jan 8, 2024

And Amplify.getConfig() only return empty object
@nadetastic

image

@JackWSargent
Copy link

@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.

@niwolf
Copy link

niwolf commented Jan 12, 2024

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

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"

@mvejca
Copy link

mvejca commented Jan 12, 2024

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

@btg5679
Copy link

btg5679 commented Jan 12, 2024

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

@Lagyu
Copy link

Lagyu commented Jan 29, 2024

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.

@ayepRahman
Copy link

ayepRahman commented Feb 3, 2024

For those whom added manual config like me, extend your config with type ResourcesConfig coming from aws-amplify. This help me fix the above issue.

Screenshot 2024-02-03 at 3 12 03 PM

@made2591
Copy link

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 :(

@jgabriel98
Copy link

Same situation of @made2591, also with version 6.0.28, using js (not ts),
migration from amplify v3 to amplify v6

old (amplify v3) Amplify.configure() call:

Amplify.configure({
  aws_project_region: process.env.REACT_APP_AWS_PROJECT_REGION,
  aws_cognito_identity_pool_id: process.env.REACT_APP_AWS_COGNITO_IDENT_POOL,
  aws_cognito_region: process.env.REACT_APP_AWS_PROJECT_REGION,
  aws_user_pools_id: process.env.REACT_APP_AWS_USER_POOL_ID,
  aws_user_pools_web_client_id: process.env.REACT_APP_AWS_WEB_CLIENT,
  oauth: {
    domain: process.env.REACT_APP_AWS_COGNITO_DOMAINANME,
    scope: [
      'phone',
      'email',
      'openid',
      'profile',
      'aws.cognito.signin.user.admin'
    ],
    redirectSignIn: process.env.REACT_APP_AWS_REDIRECT_SIGN_IN_BEYOND,
    redirectSignOut: process.env.REACT_APP_AWS_REDIRECT_SIGN_IN_BEYOND,
    responseType: 'code'
  },
  federationTarget: 'COGNITO_USER_POOLS'
})

new (amplify v6) Amplify.configure() call:

Amplify.configure({
  Auth: {
    identityPoolId: process.env.REACT_APP_AWS_COGNITO_IDENT_POOL,
    region: process.env.REACT_APP_AWS_PROJECT_REGION,
    userPoolWebClientId: process.env.REACT_APP_AWS_WEB_CLIENT,
    mandatorySignIn: true,

    Cognito: {
      userPoolId: process.env.REACT_APP_AWS_USER_POOL_ID,
      userPoolClientId: process.env.REACT_APP_AWS_WEB_CLIENT,
      identityPoolId: process.env.REACT_APP_AWS_COGNITO_IDENT_POOL,
      signUpVerificationMethod: 'code',
      loginWith: {
        oauth: {
          domain: process.env.REACT_APP_AWS_COGNITO_DOMAINANME,
          scopes: ['phone', 'email', 'openid', 'profile', 'aws.cognito.signin.user.admin'],
          redirectSignIn: [process.env.REACT_APP_AWS_REDIRECT_SIGN_IN_BEYOND],
          redirectSignOut: [process.env.REACT_APP_AWS_REDIRECT_SIGN_OUT_BEYOND],
          responseType: 'code'
        }
      },
    },
  },
})

@made2591
Copy link

@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!

@jgabriel98
Copy link

@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!

@made2591 i`ll try, thanks.

@jgabriel98
Copy link

@made2591
i ran this exact code, and still got the same error

Amplify.configure({
  Auth: {
    identityPoolId: process.env.REACT_APP_AWS_COGNITO_IDENT_POOL,
    region: process.env.REACT_APP_AWS_PROJECT_REGION,
    userPoolWebClientId: process.env.REACT_APP_AWS_WEB_CLIENT,
    mandatorySignIn: true,
  
    Cognito: {
      userPoolId: process.env.REACT_APP_AWS_USER_POOL_ID,
      userPoolClientId: process.env.REACT_APP_AWS_WEB_CLIENT,
      identityPoolId: process.env.REACT_APP_AWS_COGNITO_IDENT_POOL,
      signUpVerificationMethod: 'code',
      loginWith: {
        oauth: {
          domain: process.env.REACT_APP_AWS_COGNITO_DOMAINANME,
          scopes: ['phone', 'email', 'openid', 'profile', 'aws.cognito.signin.user.admin'],
          redirectSignIn: [process.env.REACT_APP_AWS_REDIRECT_SIGN_IN_BEYOND],
          redirectSignOut: [process.env.REACT_APP_AWS_REDIRECT_SIGN_OUT_BEYOND],
          responseType: 'code',
        }
      },
    },
  },
  })
await signInWithRedirect({ provider, customState })

@JustinHaut
Copy link

I upgraded from v5 and I'm getting the same error from the promise rejection, but interestingly in error.message it gives [UserAlreadyAuthenticatedException: There is already a signed in user.]

@AbeEstrada
Copy link

For future reference, here it is the configuration template:

https://docs.amplify.aws/gen1/javascript/tools/libraries/configure-categories/#authentication-amazon-cognito

@TheUncharted
Copy link

TheUncharted commented May 10, 2024

Hi everyone

I got the same error

As previous comments said :

  • I upgraded amplify : "aws-amplify": "^6.3.0",
  • then I removed the @aws-amplify/auth from the package.json and update the import where i used it
  • and changed my config to :
 {
	Auth: {
		Cognito: {
			userPoolClientId: "xxxxx",
			userPoolId: "xxxxx",
			identityPoolId: "xxxxx",
			signUpVerificationMethod: "code",
			loginWith: {
				// Optional
				oauth: {
					domain: "xxxxx",
					scopes: ["email", "openid", "profile", "aws.cognito.signin.user.admin"],
					redirectSignIn: ["http://localhost:3000/"],
					redirectSignOut: ["http://localhost:3000/"],
					responseType: "code"
				},
				username: "true",
				email: "false", // Optional
				phone: "false" // Optional
			}
		}
	}
};```

and it worked 
thanks to everyone 💯 

@AbeEstrada
Copy link

AbeEstrada commented May 10, 2024

For reference, I found another undocumented option allowGuestAccess, it is hidden here

Amplify.configure({
  Auth: {
    Cognito: {
      ...
      allowGuestAccess: true|false
      ...
    }
  }
});

@wootencl
Copy link

wootencl commented May 18, 2024

Also running into this issue. Tokens come back fine but for whatever reason the setAuthConfig on the TokenStore never gets set which causes the error in question. Will continue debugging but absolutely flummoxed as to what's up (spent several hours trying to dig through the source).

@wootencl
Copy link

Did a bit more digging and it's pretty amazing. Developing with react-native and expo. Tracing the logs the issue stems from intermixing esm and cjs. As it stands when I call configure the initSingleton.js file is used. The real problem occurs though then it calls setAuthConfig. For some reason that calls out to CognitoUserPoolsTokenProvider.mjs. This causes issues later on as the auth config context has now been set on the ESM/mjs side and not the CJS side. Definitely a head scratcher. Hoping I can get it sorted but any guidance would be greatly appreciated.

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 documentation Related to documentation feature requests pending-response Issue is pending response from the issue requestor question General question
Projects
None yet
Development

No branches or pull requests