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.41k stars 2.11k forks source link

Hub Auth events are not coming in anymore after upgrading aws-amplify to version 5.0.16 #11050

Closed nclaeys closed 1 year ago

nclaeys commented 1 year ago

Before opening, please confirm:

JavaScript Framework

React

Amplify APIs

Authentication

Amplify Categories

auth

Environment information

``` # Put output below this line ❯ npx envinfo --system --binaries --browsers --npmPackages --duplicates --npmGlobalPackages System: OS: Linux 5.19 Ubuntu 22.04.2 LTS 22.04.2 LTS (Jammy Jellyfish) CPU: (8) x64 Intel(R) Core(TM) i7-10610U CPU @ 1.80GHz Memory: 14.37 GB / 30.99 GB Container: Yes Shell: 5.8.1 - /usr/bin/zsh Binaries: Node: 18.12.1 - ~/.nvm/versions/node/v18.12.1/bin/node Yarn: 1.22.19 - /usr/bin/yarn npm: 8.19.2 - ~/.nvm/versions/node/v18.12.1/bin/npm Browsers: Chromium: 110.0.5481.100 Firefox: 110.0.1 npmPackages: 16: ^0.0.2 => 0.0.2 @ant-design/icons: 5.0.1 => 5.0.1 (4.8.0) @ant-design/pro-layout: 7.8.3 => 7.8.3 @auth0/auth0-spa-js: 1.22.5 => 1.22.5 @aws-sdk/client-ssm: 3.282.0 => 3.282.0 @aws-sdk/credential-providers: 3.282.0 => 3.282.0 @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/svelte: 0.0.0-development @cypress/vue: 0.0.0-development @cypress/vue2: 0.0.0-development @reduxjs/toolkit: 1.9.3 => 1.9.3 @reduxjs/toolkit-query: 1.0.0 @reduxjs/toolkit-query-react: 1.0.0 @rollup/plugin-image: 3.0.2 => 3.0.2 @rtk-query/codegen-openapi: 1.0.0 => 1.0.0 @testing-library/cypress: 9.0.0 => 9.0.0 @testing-library/jest-dom: 5.16.5 => 5.16.5 @testing-library/react: 12.1.5 => 12.1.5 @testing-library/react-hooks: 8.0.1 => 8.0.1 @testing-library/user-event: 14.4.3 => 14.4.3 @types/react: 17.0.45 => 17.0.45 @types/react-dom: 18.0.5 => 18.0.5 (17.0.17) @types/react-router-dom: 5.3.3 => 5.3.3 @typescript-eslint/eslint-plugin: 5.54.0 => 5.54.0 @typescript-eslint/parser: 5.54.0 => 5.54.0 @uiw/react-markdown-preview: 4.1.9 => 4.1.9 @uiw/react-md-editor: 3.20.5 => 3.20.5 @vitejs/plugin-react: 3.1.0 => 3.1.0 @vitest/coverage-c8: ^0.29.2 => 0.29.2 @vitest/ui: 0.29.2 => 0.29.2 amazon-cognito-identity-js: 6.1.2 => 6.1.2 antd: 5.2.3 => 5.2.3 aws-amplify: 5.0.16 => 5.0.16 c8: 7.13.0 => 7.13.0 cypress: 12.7.0 => 12.7.0 dayjs: 1.11.7 => 1.11.7 eslint: 8.35.0 => 8.35.0 eslint-config-airbnb: 19.0.4 => 19.0.4 eslint-config-airbnb-typescript: 17.0.0 => 17.0.0 eslint-config-prettier: 8.6.0 => 8.6.0 eslint-plugin-cypress: 2.12.1 => 2.12.1 eslint-plugin-import: 2.27.5 => 2.27.5 eslint-plugin-jsx-a11y: 6.7.1 => 6.7.1 eslint-plugin-prettier: 4.2.1 => 4.2.1 eslint-plugin-react: 7.32.2 => 7.32.2 eslint-plugin-react-hooks: 4.6.0 => 4.6.0 history: 5.3.0 => 5.3.0 jsdom: 21.1.0 => 21.1.0 jsonwebtoken: 9.0.0 => 9.0.0 jwt-decode: 3.1.2 => 3.1.2 less: 4.1.3 => 4.1.3 lodash: 4.17.21 => 4.17.21 lottie-react: 2.4.0 => 2.4.0 mq-polyfill: 1.1.8 => 1.1.8 msw: 1.0.1 => 1.0.1 ncp: 2.0.0 => 2.0.0 patch-package: ^6.5.1 => 6.5.1 prettier: 2.8.4 => 2.8.4 query-string: 8.1.0 => 8.1.0 react: 17.0.2 => 17.0.2 (18.2.0) react-app-polyfill: 3.0.0 => 3.0.0 react-copy-to-clipboard: 5.1.0 => 5.1.0 react-dom: 17.0.2 => 17.0.2 react-gtm-module: 2.0.11 => 2.0.11 react-redux: 8.0.5 => 8.0.5 react-resize-detector: 8.0.4 => 8.0.4 (7.1.2) react-router: 6.8.2 => 6.8.2 react-router-dom: 6.8.2 => 6.8.2 react-uuid: 2.0.0 => 2.0.0 react-virtual: 2.10.4 => 2.10.4 recharts: 2.4.3 => 2.4.3 redux: 4.2.1 => 4.2.1 redux-devtools-extension: 2.13.9 => 2.13.9 redux-first-history: 5.1.1 => 5.1.1 rollup-plugin-visualizer: 5.9.0 => 5.9.0 simple-js-sha2-256: 1.0.7 => 1.0.7 source-map-explorer: 2.5.3 => 2.5.3 ts-node: 10.9.1 => 10.9.1 tslint: 5.20.1 => 5.20.1 tslint-config-airbnb: 5.11.2 => 5.11.2 tslint-config-prettier: 1.18.0 => 1.18.0 typescript: 4.9.5 => 4.9.5 (4.5.5, 3.9.10) ua-parser-js: ^1.0.34 => 1.0.34 unique-names-generator: ^4.7.1 => 4.7.1 use-deep-compare-effect: 1.8.1 => 1.8.1 use-query-params: 2.2.0 => 2.2.0 use-query-params/adapters/reach: undefined () use-query-params/adapters/react-router-5: undefined () use-query-params/adapters/react-router-6: undefined () use-query-params/adapters/window: undefined () uuid: 9.0.0 => 9.0.0 (3.4.0, 8.3.2) vite: 4.1.4 => 4.1.4 vite-plugin-checker: 0.5.6 => 0.5.6 vite-plugin-env-compatible: 1.1.1 => 1.1.1 vite-plugin-imp: 2.3.1 => 2.3.1 vite-plugin-svgr: 2.4.0 => 2.4.0 vitest: 0.29.2 => 0.29.2 whatwg-fetch: 3.6.2 => 3.6.2 npmGlobalPackages: corepack: 0.14.2 npm: 8.19.2 ```

Describe the bug

We use aws-amplify and cognito to perform federated logins. When upgrading from version 5.0.15 to 5.0.16 our login gets stuck. While troubleshooting what happens, we notice that we do not get any events in from the hub. Sample of the code we use:

    Hub.listen('auth', (data) => {
        switch (data.payload.event) {
            case 'signIn':
                onSuccess(data.payload.data.getSignInUserSession());
                break;
            case 'customOAuthState':
                // eslint-disable-next-line no-case-declarations
                onRedirectCallback(appState.pathname, appState.search);
                break;
        }
    });

When reverting back to theold version, we do get the following events: parsingCallbackUrl codeFlow configured signIn cognitoHostedUI

Based on the release notes I do not see an obvious reason why this does not work anymore, can you give me some more insights?

Expected behavior

We should get the signin event such that we can complete the signin and redirect the user to the correct page.

Reproduction steps

install 5.0.16 and change nothing else web app is stuck

Code Snippet

// Put your code below this line.

Log output

``` // Put your logs below this line [DEBUG] 16:56.41 AuthClass - configure Auth [DEBUG] 16:56.41 Parser - parse config (3) [{…}, 'to amplifyconfig', {…}]0: {} [DEBUG] 16:56.42 Hub - Dispatching to auth with {event: 'parsingCallbackUrl', data: {…}, message: 'The callback url is being parsed'} [DEBUG] 16:56.44 OAuth - Starting code flow with http://localhost:3000/cognito?code=.... [DEBUG] 16:56.45 Hub - Dispatching to auth with {event: 'codeFlow', data: {…}, message: 'Retrieving tokens from ...'} [DEBUG] 16:56.45 OAuth - Calling token endpoint: https://auth.dev..../oauth2/token with {grant_type: 'authorization_code', code:} [DEBUG] 16:56.46 Hub - Dispatching to auth with {event: 'configured', data: null, message: 'The Auth category has been configured successfully'} [DEBUG] 16:56.562 Hub - Dispatching to auth with {event: 'signIn', data: CognitoUser2, message: 'A user has been signed in'}[DEBUG] 16:56.562 Hub - Dispatching to auth with {event: 'cognitoHostedUI', data: CognitoUser2, message: 'A user has been signed in via Cognito Hosted UI'} [DEBUG] 16:56.563 Hub - Dispatching to auth with {event: 'customOAuthState', data: '116ceaff-8810-4472-ac47-deba65bca948', message: 'State for user ...'} ```

aws-exports.js

No response

Manual configuration

Auth.configure({ region: 'eu-west-1', userPoolId: 'eu-west-1_xxxxxx', userPoolWebClientId: 'xxxxxxxxxxxxxx', oauth: { domain: auth.dev.dataminded.cloud, scope: ['email', 'openid'], redirectSignIn: ${window.location.origin}/cognito, redirectSignOut: ${window.location.origin}/cognito, responseType: 'code', }, });

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

No response

elorzafe commented 1 year ago

Did you clear your node_modules before doing the upgrade. Do you have other @aws-amplify dependencies on your package.json?

elorzafe commented 1 year ago

Also what package manager yarn or npm? and it do you have this issue on production builds or also on dev?

tannerabread commented 1 year ago

Hi @nclaeys I was able to identify the problem and the team is preparing a release ASAP. It ended up being a duplicate version of @aws-amplify/core getting installed with v5.0.16 and v5.0.17 that should come up if you run the command shown on this page of the docs. The library sometimes has issues with Auth functionality if there are multiple core packages installed, in this case it had a core v5.1.0 and a core v5.0.15.

That being said, while the next release should solve this issue, I noticed that you have amazon-cognito-identity-js installed in your environment which shouldn't be necessary unless you are on a React Native project. I didn't see any evidence of React Native but I could be wrong.

The fix should be out within the next couple of days, if you would like to keep using v5.0.15 until v5.0.18 is released which should fix the problem. I will update this issue when the fix is released.

tannerabread commented 1 year ago

The release is out if you would like to try v5.0.18 and see if that solves your issue!

nclaeys commented 1 year ago

@tannerabread Thanks a lot for the fix. Validated it and indeed the issue is solved. Thanks for the remark about amazon-cognito-identity-js, we initially used it in the legacy login flow and probably forgot to remove it after migrating. I will look into it.

tannerabread commented 1 year ago

Glad it fixed the problem! I will close this issue for now but please let me know if you find anything different about amazon-cognito-identity-js and it was still necessary for your project.

Thank you for opening this issue and bringing this bug to our attention!

nclaeys commented 1 year ago

@tannerabread we do not really need it, we only use it for typing. We depend on the following classes: CognitoAccessToken,CognitoIdToken, CognitoUser, CognitoUserSession. Our linter is configured to complain if we do not explicitly depend on the package even though it is a transitive dependency.

tannerabread commented 1 year ago

Oh I see, thanks for the clarity!

nclaeys commented 1 year ago

@tannerabread It seems that I have the same issue again when upgrading from aws-amplify 5.3.7 -> 5.3.8. In the latest version I do not receive any of the callback url events from the event hub anymore.