From fde2682681edffa5b1d80432e5604db189406aae Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Fri, 13 Nov 2020 04:30:05 +0100 Subject: [PATCH] Simplyfied login guard, fixed exception in RoleSettings --- src/boot/login.ts | 34 ++++++------ src/config.ts | 2 +- .../user/components/settings/RoleSettings.vue | 55 ++++++++++++------- 3 files changed, 53 insertions(+), 38 deletions(-) diff --git a/src/boot/login.ts b/src/boot/login.ts index 6c8baf5..06582ac 100644 --- a/src/boot/login.ts +++ b/src/boot/login.ts @@ -7,7 +7,17 @@ export default boot>(({ router, store }) => { router.beforeEach((to, from, next) => { const session = store.state.session.currentSession; - if (to.name != 'login') { + if (to.path.startsWith('/main')) { + // Secured area (LOGIN REQUIRED) + // Check login is ok + if (!session || session.expires <= new Date()) { + store.dispatch('session/logout').catch(error => { + console.warn(error); + }); + return; + } + + // Check if special permissions are required if ( to.matched.every((record: RouteRecord) => { if (!('meta' in record) || !('permissions' in record.meta)) @@ -23,30 +33,20 @@ export default boot>(({ router, store }) => { } }) ) { - if ( - !to.matched.every((record: RouteRecord) => { - if (!('meta' in record) || !('permissions' in record.meta)) - return true; - else return false; - }) - ) { - if (!session || session.expires <= new Date()) { - store.dispatch('session/logout').catch(error => { - console.warn(error); - }); - return; - } - } next(); } else { next({ name: 'login', query: { redirect: to.fullPath } }); } } else { - if (store.state.user.currentUser && !to.params['logout']) { + if ( + to.name == 'login' && + store.state.user.currentUser && + !to.params['logout'] + ) { // Called login while already logged in void next({ name: 'dashboard' }); } else { - // Not logged in or from logout + // We are on the non secured area next(); } } diff --git a/src/config.ts b/src/config.ts index 9a1e011..90b3ca8 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,5 +1,5 @@ const config = { - baseURL: 'https://flaschengeist.duckdns.org/api' + baseURL: '/api' }; export default config; diff --git a/src/plugins/user/components/settings/RoleSettings.vue b/src/plugins/user/components/settings/RoleSettings.vue index d5aa767..1123e6b 100644 --- a/src/plugins/user/components/settings/RoleSettings.vue +++ b/src/plugins/user/components/settings/RoleSettings.vue @@ -1,16 +1,17 @@