From f2b7f3a3b4996a9ce0ee17cffc5f473bce6c6fa5 Mon Sep 17 00:00:00 2001 From: groegert Date: Fri, 21 May 2021 10:17:56 +0200 Subject: [PATCH 1/4] [core] call api.delete(`auth/${token}`) within a valid session fixes: #7 --- src/stores/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stores/index.ts b/src/stores/index.ts index 319bd9d..c1dd227 100644 --- a/src/stores/index.ts +++ b/src/stores/index.ts @@ -80,11 +80,11 @@ export const useMainStore = defineStore({ try { const token = this.session.token; + await api.delete(`/auth/${token}`); this.$patch({ session: undefined, user: undefined, }); - await api.delete(`/auth/${token}`); } catch (error) { return false; } finally { From 9940589d1ac42f40f1761bd9b53f89ec4257f9ec Mon Sep 17 00:00:00 2001 From: groegert Date: Mon, 24 May 2021 19:21:49 +0200 Subject: [PATCH 2/4] [core] prevent recursive logouts on htto-401 fixes #7 --- src/boot/axios.ts | 4 ++-- src/boot/plugins.ts | 3 ++- src/stores/index.ts | 17 ++++++++++------- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/boot/axios.ts b/src/boot/axios.ts index 07bf177..507a44f 100644 --- a/src/boot/axios.ts +++ b/src/boot/axios.ts @@ -22,7 +22,7 @@ export default boot(({ router }) => { /*** * Intercept responses - * - filter 401 --> logout + * - filter 401 --> handleLoggedOut * - filter timeout or 502-504 --> backendOffline */ api.interceptors.response.use( @@ -45,7 +45,7 @@ export default boot(({ router }) => { query: { redirect: next }, }); } else if (e.response && e.response.status == 401) { - void store.logout(); + void store.handleLoggedOut(); if (current.name !== 'login') { await router.push({ name: 'login', diff --git a/src/boot/plugins.ts b/src/boot/plugins.ts index 4966893..ba86449 100644 --- a/src/boot/plugins.ts +++ b/src/boot/plugins.ts @@ -10,7 +10,8 @@ const config: { [key: string]: Array } = { // Do not change required Modules !! requiredModules: ['User'], // here you can import plugins. - loadModules: ['Balance', 'Schedule', 'Pricelist'], + //loadModules: ['Balance', 'Schedule', 'Pricelist'], + loadModules: [], }; /* Stop! diff --git a/src/stores/index.ts b/src/stores/index.ts index c1dd227..681d048 100644 --- a/src/stores/index.ts +++ b/src/stores/index.ts @@ -76,19 +76,13 @@ export const useMainStore = defineStore({ async logout() { if (!this.session || !this.session.token) return false; - LocalStorage.clear(); - try { const token = this.session.token; await api.delete(`/auth/${token}`); - this.$patch({ - session: undefined, - user: undefined, - }); } catch (error) { return false; } finally { - SessionStorage.clear(); + this.handleLoggedOut( ); } return true; }, @@ -151,6 +145,15 @@ export const useMainStore = defineStore({ async setShortcuts() { await api.put(`users/${this.currentUser.userid}/shortcuts`, this.shortcuts); }, + handleLoggedOut() { + LocalStorage.clear(); + + this.$patch({ + session: undefined, + user: undefined, + }); + SessionStorage.clear(); + }, }, }); From 625ac55b0a2e88b18e008e2ced4974363c4eca4d Mon Sep 17 00:00:00 2001 From: groegert Date: Mon, 24 May 2021 19:30:28 +0200 Subject: [PATCH 3/4] [core] prevent recursive logouts on htto-401 fixes #7 --- src/boot/login.ts | 2 +- src/boot/plugins.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/boot/login.ts b/src/boot/login.ts index c1dfca5..21533b5 100644 --- a/src/boot/login.ts +++ b/src/boot/login.ts @@ -13,7 +13,7 @@ export default boot(({ router }) => { // Secured area (LOGIN REQUIRED) // Check login is ok if (!store.session || store.session.expires <= new Date()) { - void store.logout(); + void store.handleLoggedOut(); return next({ name: 'login', query: { redirect: to.fullPath } }); } diff --git a/src/boot/plugins.ts b/src/boot/plugins.ts index ba86449..a496587 100644 --- a/src/boot/plugins.ts +++ b/src/boot/plugins.ts @@ -10,8 +10,8 @@ const config: { [key: string]: Array } = { // Do not change required Modules !! requiredModules: ['User'], // here you can import plugins. - //loadModules: ['Balance', 'Schedule', 'Pricelist'], - loadModules: [], + loadModules: ['Balance', 'Schedule', 'Pricelist'], + //loadModules: [], }; /* Stop! From 86bad83e53707eb81c22cb15eb8fceca55b17c72 Mon Sep 17 00:00:00 2001 From: groegert Date: Tue, 25 May 2021 12:46:54 +0200 Subject: [PATCH 4/4] [core] added computation when accessing promised store in EssentialExpansionLink fixes #9 --- src/components/navigation/EssentialExpansionLink.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/navigation/EssentialExpansionLink.vue b/src/components/navigation/EssentialExpansionLink.vue index 9c874e9..b02fdf1 100644 --- a/src/components/navigation/EssentialExpansionLink.vue +++ b/src/components/navigation/EssentialExpansionLink.vue @@ -47,7 +47,7 @@ export default defineComponent({ }, setup(props, { emit }) { function isGranted(val: FG_Plugin.MenuLink) { - return hasPermissions(val.permissions || []); + return computed(() => hasPermissions(val.permissions || [])); } const title = computed(() => typeof props.entry.title === 'function' ? props.entry.title() : props.entry.title