mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
refactor routes and route guards
This commit is contained in:
parent
2c25651db0
commit
5baeb0b0ef
@ -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()
|
||||
|
||||
@ -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: '*',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user