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.42k stars 2.12k forks source link

V6 upgrade causes AuthUserPoolException #12627

Closed pablovargasosorio closed 10 months ago

pablovargasosorio commented 10 months ago

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)

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 () 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.

rkstgr commented 10 months ago

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 commented 10 months ago

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

rkstgr commented 10 months ago

Have you downgraded both dependencies?

pablovargasosorio commented 10 months ago

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

nadetastic commented 10 months ago

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?

dkhuntrods commented 10 months ago

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 commented 10 months ago

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

pablovargasosorio commented 10 months ago

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 commented 10 months ago

@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'
pringtest commented 10 months ago

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 commented 10 months ago

@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 commented 10 months ago

Glad to have gotten your issues resolved!

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

InspiredJason commented 10 months ago

@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 commented 10 months ago

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 commented 10 months ago

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>
      </>
   )
})```
mnovati commented 10 months ago

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

InspiredJason commented 10 months ago

@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 commented 10 months ago

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 commented 10 months ago

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

OperationalFallacy commented 10 months ago

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

It's not an issue, everything is working as expected. I was incorrectly calling fetchAuthSession() on the publicly accessible page, hence it was erroring out.

nadetastic commented 10 months ago

Ok glad to hear that 😄, I'll go ahead and resolve this issue. Thank you!

willjstevens commented 10 months ago

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

mnovati commented 10 months ago

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

willjstevens commented 10 months ago

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 commented 10 months ago

I have same problem

"vue": "^3.3.4",
"aws-amplify": "6.0.2", (and 6.0.6 still not working like 6.0.2)

image

and here console.log

image

willjstevens commented 10 months ago

Look at the config structure here. https://github.com/aws-amplify/amplify-js/issues/12627#issuecomment-1848214340

tkalra commented 9 months ago

https://github.com/aws-amplify/amplify-js/issues/12627#issuecomment-1848214340 Thanks for this it worked for me aswell. I think the documentation needs to update to account for adding those under Auth as well as Cognito.

nadetastic commented 9 months ago

@tkalra Glad that you were able to get working. Could you let me know where you see the documenation needing an update? For reference, the expected configuration is documented here - https://docs.amplify.aws/react/tools/libraries/configure-categories/#authentication-amazon-cognito

cc @willjstevens

willjstevens commented 9 months ago

@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 commented 9 months ago

@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 commented 9 months ago

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

mnovati commented 9 months ago

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 commented 9 months ago

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 commented 9 months ago

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 commented 9 months ago

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

image

JackWSargent commented 8 months ago

@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 commented 8 months ago

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 commented 8 months ago

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 commented 8 months ago

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 commented 8 months ago

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 commented 8 months ago

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 commented 5 months ago

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 commented 5 months ago

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 commented 5 months ago

@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 commented 5 months ago

@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 commented 5 months ago

@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 commented 5 months ago

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 commented 5 months ago

For future reference, here it is the configuration template:

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

TheUncharted commented 4 months ago

Hi everyone

I got the same error

As previous comments said :


 {
    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 commented 4 months ago

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

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