From c0437e55ebbaec5c7fe529ff3185083ffb5575b8 Mon Sep 17 00:00:00 2001 From: Azalea <22280294+hykilpikonna@users.noreply.github.com> Date: Sun, 3 Mar 2024 12:24:20 -0500 Subject: [PATCH] [F] Fix token invalidation --- AquaNet/src/libs/sdk.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/AquaNet/src/libs/sdk.ts b/AquaNet/src/libs/sdk.ts index 77c0fb46..f5e16108 100644 --- a/AquaNet/src/libs/sdk.ts +++ b/AquaNet/src/libs/sdk.ts @@ -64,14 +64,6 @@ export async function post(endpoint: string, params: any, init?: RequestInitWith }).catch(e => { console.error(e) - // If 400 invalid token is caught, should invalidate the token and redirect to signin - if (e.message === 'Invalid token') { - // Invalidate token - localStorage.removeItem('token') - // Redirect to signin - window.location.href = '/' - } - throw new Error('Network error') }) @@ -79,6 +71,12 @@ export async function post(endpoint: string, params: any, init?: RequestInitWith const text = await res.text() console.error(`${res.status}: ${text}`) + // If 400 invalid token is caught, should invalidate the token and redirect to signin + if (text === 'Invalid token') { + localStorage.removeItem('token') + window.location.href = '/' + } + // Try to parse as json let json try {