From 28401867c783d96b1d1c5bbbc5c96980188e8a08 Mon Sep 17 00:00:00 2001 From: Hassan Abouelela Date: Thu, 14 Jul 2022 11:06:08 +0400 Subject: Clear Authorization On Error Deletes the OAuth cookies when an error happens during submit. This is a stopgap till we fix the authorization issues. Signed-off-by: Hassan Abouelela --- src/api/auth.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/api/auth.ts') diff --git a/src/api/auth.ts b/src/api/auth.ts index de6210e..638d8d2 100644 --- a/src/api/auth.ts +++ b/src/api/auth.ts @@ -207,12 +207,21 @@ export async function refreshBackendJWT(): Promise { setTimeout(refreshBackendJWT, ((expiry - Date.now()) / 1000 * 0.9)); }).catch(() => { pass = false; - cookies.remove(CookieNames.Scopes); + cookies.remove(CookieNames.Scopes, {path: "/"}); }); return new Promise(resolve => resolve(pass)); } +/** + * Clear the auth state. + */ +export function clearAuth(): void { + const cookies = new Cookies(); + cookies.remove(CookieNames.Scopes, {path: "/"}); + cookies.remove(CookieNames.Username, {path: "/"}); +} + /** * Handle a full authorization flow. Sets a cookie with the JWT and scopes. * @@ -228,7 +237,7 @@ export default async function authorize(scopes: OAuthScopes[] = [], disableFunct } const cookies = new Cookies; - cookies.remove(CookieNames.Scopes); + cookies.remove(CookieNames.Scopes, {path: "/"}); if (disableFunction) { disableFunction(true); } await getDiscordCode(scopes, disableFunction).then(async discord_response =>{ -- cgit v1.2.3