separate router.beforeach & implement the authenticate route

This commit is contained in:
Ulf Gebhardt 2021-11-19 20:54:49 +01:00
parent 82356dceb4
commit c5ec31343c
Signed by: ulfgebhardt
GPG Key ID: DA6B843E748679C9
2 changed files with 21 additions and 2 deletions

View File

@ -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 {

View File

@ -1,6 +1,9 @@
import NotFound from '@/views/NotFoundPage.vue'
const routes = [
{
path: '/authenticate',
},
{
path: '/',
redirect: (to) => {