From 79a078fb70bac5eb457b0b6e59e341e5c73ca2e3 Mon Sep 17 00:00:00 2001 From: Azalea <22280294+hykilpikonna@users.noreply.github.com> Date: Wed, 21 Feb 2024 17:42:42 -0500 Subject: [PATCH] [+] Automatically invalidate token on expiry --- AquaNet/src/libs/sdk.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/AquaNet/src/libs/sdk.ts b/AquaNet/src/libs/sdk.ts index 94ecafbb..86e03835 100644 --- a/AquaNet/src/libs/sdk.ts +++ b/AquaNet/src/libs/sdk.ts @@ -45,6 +45,15 @@ export async function post(endpoint: string, params: any, init?: RequestInitWith ...init }).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') })