From f731f0d4533846f21fa76df55cee791bbc58861f Mon Sep 17 00:00:00 2001 From: spiral Date: Thu, 2 Jun 2022 23:12:38 -0400 Subject: [PATCH] fix(dashboard): only clear token from localStorage on 401 error --- dashboard/src/pages/Dash.svelte | 6 +++--- dashboard/src/pages/Home.svelte | 9 ++++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/dashboard/src/pages/Dash.svelte b/dashboard/src/pages/Dash.svelte index 73ddda6b..dec5190b 100644 --- a/dashboard/src/pages/Dash.svelte +++ b/dashboard/src/pages/Dash.svelte @@ -58,9 +58,9 @@ user = res; } catch (error) { console.log(error); - localStorage.removeItem("pk-token"); - localStorage.removeItem("pk-user"); - currentUser.update(() => null); + // localStorage.removeItem("pk-token"); + // localStorage.removeItem("pk-user"); + // currentUser.update(() => null); navigate("/"); } } diff --git a/dashboard/src/pages/Home.svelte b/dashboard/src/pages/Home.svelte index 3998f734..c7acdcfa 100644 --- a/dashboard/src/pages/Home.svelte +++ b/dashboard/src/pages/Home.svelte @@ -47,9 +47,12 @@ currentUser.update(() => res); } catch (error) { console.log(error); - localStorage.removeItem("pk-token"); - localStorage.removeItem("pk-user"); - currentUser.update(() => null); + if (error.code == 401) { + error.message = "Invalid token"; + localStorage.removeItem("pk-token"); + localStorage.removeItem("pk-user"); + currentUser.update(() => null); + } err = error.message; } loading = false;