From 5baeb0b0ef9ea027604ccb7ff9058a8e40b9ed91 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Fri, 19 Nov 2021 19:56:37 +0100 Subject: [PATCH] refactor routes and route guards --- admin/src/router/guards.js | 18 +++++++++++++++++- admin/src/router/routes.js | 28 ++++++---------------------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/admin/src/router/guards.js b/admin/src/router/guards.js index c9baf61cb..d6eeda927 100644 --- a/admin/src/router/guards.js +++ b/admin/src/router/guards.js @@ -1,7 +1,23 @@ const addNavigationGuards = (router, store) => { + // store token on authenticate router.beforeEach((to, from, next) => { + console.log('token', to.path, from.path, to.query) // handle authentication - if (to.meta.requiresAuth && !store.state.token) { + if (to.path === '/authenticate' && to.query.token) { + console.log('token', to.query.token, to) + store.commit('token',to.query.token) + // to.query = {} + next({path: '/'}) + } else { + next() + } + }) + + // protect all routes but not-found + router.beforeEach((to, from, next) => { + console.log('protect', to.path, from.path) + // handle authentication + if (!store.state.token && to.path !== '/not-found') { next({ path: '/not-found' }) } else { next() diff --git a/admin/src/router/routes.js b/admin/src/router/routes.js index a13463e08..31008824d 100644 --- a/admin/src/router/routes.js +++ b/admin/src/router/routes.js @@ -1,38 +1,22 @@ const routes = [ { - path: '/', - component: () => import('@/views/Overview.vue'), - meta: { - requiresAuth: true, - }, + path: '/authenticate', }, { - path: '/overview', - component: () => import('@/views/Overview.vue'), - meta: { - requiresAuth: true, - }, + path: '/', + component: () => import('@/pages/Overview.vue'), }, { path: '/user', - component: () => import('@/views/UserSearch.vue'), - meta: { - requiresAuth: true, - }, + component: () => import('@/pages/UserSearch.vue'), }, { path: '/creation', - component: () => import('@/views/Creation.vue'), - meta: { - requiresAuth: true, - }, + component: () => import('@/pages/Creation.vue'), }, { path: '/creation-confirm', - component: () => import('@/views/CreationConfirm.vue'), - meta: { - requiresAuth: true, - }, + component: () => import('@/pages/CreationConfirm.vue'), }, { path: '*',