Skip to content

Commit

Permalink
Reset auth button when auth window close regardless of flow state (#2311
Browse files Browse the repository at this point in the history
)
  • Loading branch information
gxueatlassian authored Aug 4, 2023
1 parent 4d19f63 commit 01faeb8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 3 additions & 1 deletion spa/src/pages/ConfigSteps/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 }));
Expand Down
12 changes: 10 additions & 2 deletions spa/src/services/oauth-manager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,19 @@ async function checkValidity(): Promise<boolean | AxiosError> {
}
}

async function authenticateInGitHub(): Promise<void> {
async function authenticateInGitHub(onWinClosed: () => void): Promise<void> {
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);
}
}
}

Expand Down

0 comments on commit 01faeb8

Please sign in to comment.