diff options
author | 2021-03-07 18:47:54 +0300 | |
---|---|---|
committer | 2021-03-07 18:47:54 +0300 | |
commit | 71388eb70fe9514c98ff362349fb45c06349bb74 (patch) | |
tree | af3c8645d78c2e77c627fa1c2517d2171e7b206f /src/api | |
parent | Revert "Removes Unused OAuth Cleaning" (diff) |
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 <[email protected]>
Diffstat (limited to 'src/api')
-rw-r--r-- | src/api/auth.ts | 5 |
1 files changed, 3 insertions, 2 deletions
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); |