From ad5c83e05e2c32c9f23ff61a8f10395148f5757e Mon Sep 17 00:00:00 2001 From: Jim Blanchard Date: Tue, 31 Oct 2023 18:20:41 -0500 Subject: [PATCH] fix: Support tracking multiple inflight OAuth promise resolvers (#12482) --- packages/auth/package.json | 4 ++-- .../src/providers/cognito/apis/signInWithRedirect.ts | 11 +++++++---- packages/aws-amplify/package.json | 4 ++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/packages/auth/package.json b/packages/auth/package.json index 465b9ba944d..c36d03ff74e 100644 --- a/packages/auth/package.json +++ b/packages/auth/package.json @@ -7,8 +7,8 @@ "typings": "./lib-esm/index.d.ts", "react-native": "./lib-esm/index.js", "sideEffects": [ - "./lib/providers/cognito/apis/signInWithOAuth.js", - "./lib-esm/providers/cognito/apis/signInWithOAuth.js" + "./lib/providers/cognito/apis/signInWithRedirect.js", + "./lib-esm/providers/cognito/apis/signInWithRedirect.js" ], "publishConfig": { "access": "public" diff --git a/packages/auth/src/providers/cognito/apis/signInWithRedirect.ts b/packages/auth/src/providers/cognito/apis/signInWithRedirect.ts index 42855e4813a..a5004e499bc 100644 --- a/packages/auth/src/providers/cognito/apis/signInWithRedirect.ts +++ b/packages/auth/src/providers/cognito/apis/signInWithRedirect.ts @@ -461,11 +461,14 @@ function urlListener() { isBrowser() && urlListener(); // This has a reference for listeners that requires to be notified, TokenOrchestrator use this for load tokens -let resolveInflightPromise = () => {}; +let inflightPromiseResolvers: ((value: void | PromiseLike) => void)[] = + []; const invokeAndClearPromise = () => { - resolveInflightPromise(); - resolveInflightPromise = () => {}; + for (const promiseResolver of inflightPromiseResolvers) { + promiseResolver(); + } + inflightPromiseResolvers = []; }; isBrowser() && @@ -475,7 +478,7 @@ isBrowser() && if (!(await store.loadOAuthInFlight())) { res(); } else { - resolveInflightPromise = res; + inflightPromiseResolvers.push(res); } return; }) diff --git a/packages/aws-amplify/package.json b/packages/aws-amplify/package.json index 88374a9579d..e9d1fe42a8f 100644 --- a/packages/aws-amplify/package.json +++ b/packages/aws-amplify/package.json @@ -340,7 +340,7 @@ "name": "[Auth] confirmSignIn (Cognito)", "path": "./lib-esm/auth/index.js", "import": "{ confirmSignIn }", - "limit": "25.48 kB" + "limit": "25.55 kB" }, { "name": "[Auth] updateMFAPreference (Cognito)", @@ -412,7 +412,7 @@ "name": "[Auth] OAuth Auth Flow (Cognito)", "path": "./lib-esm/auth/index.js", "import": "{ signInWithRedirect, signOut, fetchAuthSession }", - "limit": "19.53 kB" + "limit": "19.61 kB" }, { "name": "[Storage] copy (S3)",