From 297543f9dd1f3bfbb9233fea5d65290012ec4f22 Mon Sep 17 00:00:00 2001 From: Ali BARIN Date: Thu, 5 Sep 2024 12:08:32 +0000 Subject: [PATCH] feat(useAuthenticateApp): early exit connection creation at blocked pop-up --- .../src/components/AddAppConnection/index.jsx | 8 +----- .../web/src/hooks/useAuthenticateApp.ee.js | 26 ++++++++++--------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/packages/web/src/components/AddAppConnection/index.jsx b/packages/web/src/components/AddAppConnection/index.jsx index c1c47743..2d1b468c 100644 --- a/packages/web/src/components/AddAppConnection/index.jsx +++ b/packages/web/src/components/AddAppConnection/index.jsx @@ -31,7 +31,7 @@ function AddAppConnection(props) { const hasConnection = Boolean(connectionId); const useShared = searchParams.get('shared') === 'true'; const appAuthClientId = searchParams.get('appAuthClientId') || undefined; - const { authenticate, isPopupBlocked } = useAuthenticateApp({ + const { authenticate } = useAuthenticateApp({ appKey: key, connectionId, appAuthClientId, @@ -134,12 +134,6 @@ function AddAppConnection(props) { )} - {isPopupBlocked && ( - - {formatMessage('addAppConnection.popupReminder')} - - )} - {error && ( { @@ -37,6 +38,7 @@ export default function useAuthenticateApp(payload) { return async function authenticate(payload = {}) { const { fields } = payload; setAuthenticationInProgress(true); + const response = { key: appKey, appAuthClientId: appAuthClientId || payload.appAuthClientId, @@ -50,17 +52,18 @@ export default function useAuthenticateApp(payload) { while (stepIndex < steps?.length) { const step = steps[stepIndex]; const variables = computeAuthStepVariables(step.arguments, response); - let popup; - - if (step.type === 'openWithPopup') { - popup = processOpenWithPopup(variables.url); - - if (!popup) { - setPopupBlocked(true); - } - } try { + let popup; + + if (step.type === 'openWithPopup') { + popup = processOpenWithPopup(variables.url); + + if (!popup) { + throw new Error(formatMessage('addAppConnection.popupReminder')); + } + } + if (step.type === 'mutation') { const stepResponse = await processMutation(step.name, variables); response[step.name] = stepResponse; @@ -81,11 +84,10 @@ export default function useAuthenticateApp(payload) { setAuthenticationInProgress(false); } }; - }, [steps, appKey, appAuthClientId, connectionId]); + }, [steps, appKey, appAuthClientId, connectionId, formatMessage]); return { authenticate, - isPopupBlocked, inProgress: authenticationInProgress, }; }