From 896fff04aae2d9883338ff3b6b6333be8ee650d4 Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Fri, 19 Feb 2021 18:49:07 +0100 Subject: [PATCH] Fixed non-automatic logout closes #38 --- src/App.svelte | 6 ++++++ src/store.js | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/App.svelte b/src/App.svelte index cec35a20..f7bfc82e 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -27,6 +27,12 @@ storeName: "lfk_admin", description: "LfK! admin dashbaord", }); + window.onunhandledrejection = event => { + if(event.reason.toString() == "Error: Unauthorized"){ + console.log("Found 1") + localForage.clear(); + location.replace("/"); + }}; // import Login from "./components/auth/Login.svelte"; import Dashboard from "./components/dashboard/Dashboard.svelte"; diff --git a/src/store.js b/src/store.js index 8fefe738..20ca595b 100644 --- a/src/store.js +++ b/src/store.js @@ -28,7 +28,7 @@ const store = () => { const jwtinfo = JSON.parse(atob(auth.access_token.split('.')[1])); state.jwtinfo = jwtinfo; localForage.setItem('logindata', auth); - }); + }).catch(this.logout()); }, login(auth, jwtinfo) { update((state) => {