aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Hassan Abouelela <[email protected]>2022-07-14 11:06:08 +0400
committerGravatar Hassan Abouelela <[email protected]>2022-07-14 11:06:08 +0400
commit28401867c783d96b1d1c5bbbc5c96980188e8a08 (patch)
tree477182518fb66d0a45bc748fbcfd65b822747ecf
parentMerge pull request #483 from python-discord/dependabot/npm_and_yarn/swc/core-... (diff)
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 <[email protected]>
-rw-r--r--src/api/auth.ts13
-rw-r--r--src/pages/FormPage/ErrorPage.tsx3
2 files changed, 14 insertions, 2 deletions
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,13 +207,22 @@ export async function refreshBackendJWT(): Promise<boolean> {
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.
*
* @param scopes The scopes that should be authorized for the application.
@@ -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 =>{
diff --git a/src/pages/FormPage/ErrorPage.tsx b/src/pages/FormPage/ErrorPage.tsx
index 9a7fad9..da336cf 100644
--- a/src/pages/FormPage/ErrorPage.tsx
+++ b/src/pages/FormPage/ErrorPage.tsx
@@ -6,6 +6,7 @@ import React from "react";
import HeaderBar from "../../components/HeaderBar";
import {Form} from "../../api/forms";
+import {clearAuth} from "../../api/auth";
import {selectable, submitStyles, unselectable} from "../../commonStyles";
import Navigation from "./Navigation";
@@ -22,6 +23,8 @@ const refreshStyles = css`
export default function ErrorPage(props: ErrorProps): JSX.Element {
+ clearAuth();
+
return (
<div>
<HeaderBar title={props.form.name} description={props.form.description}/>