From 71388eb70fe9514c98ff362349fb45c06349bb74 Mon Sep 17 00:00:00 2001 From: Hassan Abouelela <47495861+HassanAbouelela@users.noreply.github.com> Date: Sun, 7 Mar 2021 18:47:54 +0300 Subject: Renables OAuth Button On Failure Allows the Discord OAuth button to be renabled in case the window is closed prematurely. Signed-off-by: Hassan Abouelela <47495861+HassanAbouelela@users.noreply.github.com> --- src/api/auth.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/api/auth.ts b/src/api/auth.ts index 50f9a69..024292c 100644 --- a/src/api/auth.ts +++ b/src/api/auth.ts @@ -94,7 +94,7 @@ export function checkScopes(scopes?: OAuthScopes[]): boolean { * @returns {code, cleanedScopes} The discord authorization code and the scopes the code is granted for. * @throws {Error} Indicates that an integrity check failed. */ -export async function getDiscordCode(scopes: OAuthScopes[]): Promise<{code: string, cleanedScopes: OAuthScopes[]}> { +export async function getDiscordCode(scopes: OAuthScopes[], disableFunction?: (disable: boolean) => void): Promise<{code: string, cleanedScopes: OAuthScopes[]}> { const cleanedScopes = ensureMinimumScopes(scopes, OAuthScopes.Identify); // Generate a new user state @@ -114,6 +114,7 @@ export async function getDiscordCode(scopes: OAuthScopes[]): Promise<{code: stri const interval = setInterval(() => { if (windowRef?.closed) { clearInterval(interval); + if (disableFunction) { disableFunction(false); } } }, 500); @@ -231,7 +232,7 @@ export default async function authorize(scopes: OAuthScopes[] = [], disableFunct cookies.remove(CookieNames.Scopes); if (disableFunction) { disableFunction(true); } - await getDiscordCode(scopes).then(async discord_response =>{ + await getDiscordCode(scopes, disableFunction).then(async discord_response =>{ await requestBackendJWT(discord_response.code).then(backend_response => { const options: CookieSetOptions = {sameSite: "strict", secure: PRODUCTION, path: "/", expires: new Date(3000, 1)}; cookies.set(CookieNames.Username, backend_response.username, options); -- cgit v1.2.3