From c5ec31343c0164f9c6fec52501c1ef11675824c6 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Fri, 19 Nov 2021 20:54:49 +0100 Subject: [PATCH] separate router.beforeach & implement the authenticate route --- frontend/src/routes/guards.js | 20 ++++++++++++++++++-- frontend/src/routes/routes.js | 3 +++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/frontend/src/routes/guards.js b/frontend/src/routes/guards.js index eebd6976e..bb55ba0cf 100644 --- a/frontend/src/routes/guards.js +++ b/frontend/src/routes/guards.js @@ -1,12 +1,28 @@ const addNavigationGuards = (router, store) => { + // handle publisherId router.beforeEach((to, from, next) => { - // handle publisherId const publisherId = to.query.pid if (publisherId) { store.commit('publisherId', publisherId) delete to.query.pid } - // handle authentication + next() + }) + + // store token on authenticate + router.beforeEach((to, from, next) => { + console.log('token', to.path, from.path, to.query) + if (to.path === '/authenticate' && to.query.token) { + console.log('token', to.query.token, to) + store.commit('token',to.query.token) + next({path: '/overview'}) + } else { + next() + } + }) + + // handle authentication + router.beforeEach((to, from, next) => { if (to.meta.requiresAuth && !store.state.token) { next({ path: '/login' }) } else { diff --git a/frontend/src/routes/routes.js b/frontend/src/routes/routes.js index f4f0dfe04..6e7d8fadf 100755 --- a/frontend/src/routes/routes.js +++ b/frontend/src/routes/routes.js @@ -1,6 +1,9 @@ import NotFound from '@/views/NotFoundPage.vue' const routes = [ + { + path: '/authenticate', + }, { path: '/', redirect: (to) => {