From c16e71cf35a92d1b464c057d93c93c9c26774e76 Mon Sep 17 00:00:00 2001 From: Gary Xue Date: Fri, 4 Aug 2023 11:01:23 +1000 Subject: [PATCH] Reset auth button when auth window close regardless of flow state --- spa/src/pages/ConfigSteps/index.tsx | 4 +++- spa/src/services/oauth-manager/index.ts | 12 ++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/spa/src/pages/ConfigSteps/index.tsx b/spa/src/pages/ConfigSteps/index.tsx index 498b994194..0410ff1410 100644 --- a/spa/src/pages/ConfigSteps/index.tsx +++ b/spa/src/pages/ConfigSteps/index.tsx @@ -214,7 +214,9 @@ const ConfigSteps = () => { setLoaderForLogin(true); try { analyticsClient.sendUIEvent({ actionSubject: "startOAuthAuthorisation", action: "clicked", attributes: { type: "cloud" } }); - await OAuthManager.authenticateInGitHub(); + await OAuthManager.authenticateInGitHub(() => { + setLoaderForLogin(false); + }); } catch (e) { setLoaderForLogin(false); setError(modifyError(e as AxiosError, {}, { onClearGitHubToken: clearGitHubToken })); diff --git a/spa/src/services/oauth-manager/index.ts b/spa/src/services/oauth-manager/index.ts index 1fee9f3a88..083950b71a 100644 --- a/spa/src/services/oauth-manager/index.ts +++ b/spa/src/services/oauth-manager/index.ts @@ -22,11 +22,19 @@ async function checkValidity(): Promise { } } -async function authenticateInGitHub(): Promise { +async function authenticateInGitHub(onWinClosed: () => void): Promise { const res = await Api.auth.generateOAuthUrl(); if (res.data.redirectUrl && res.data.state) { window.localStorage.setItem(STATE_KEY, res.data.state); - popup(res.data.redirectUrl, { width: 400, height: 600 }); + const win = popup(res.data.redirectUrl, { width: 400, height: 600 }); + if (win) { + const winCloseCheckHandler = setInterval(() => { + if (win.closed) { + clearInterval(winCloseCheckHandler); + try { onWinClosed(); } catch (e) { reportError(e); } + } + }, 1000); + } } }