flaschengeist-frontend/src/router/index.js

71 lines
1.4 KiB
JavaScript
Raw Normal View History

2019-12-20 13:01:36 +00:00
import Vue from 'vue'
import VueRouter from 'vue-router'
2020-01-14 21:01:24 +00:00
import FinanzerView from '@/views/FinanzerView'
import Login from '@/views/Login'
import store from '@/store/index'
import BarView from '@/views/BarView'
2019-12-20 13:01:36 +00:00
Vue.use(VueRouter)
const routes = [
{
2020-01-14 21:01:24 +00:00
path: '/login',
name: 'login',
2019-12-21 07:20:25 +00:00
component: Login
2019-12-20 13:01:36 +00:00
},
{
2020-01-14 21:01:24 +00:00
path: '/finanzer',
name: 'finanzer',
2019-12-21 07:20:25 +00:00
component: FinanzerView
},
{
2020-01-14 21:01:24 +00:00
path: '/bar',
name: 'bar',
2019-12-21 07:20:25 +00:00
component: BarView
},
{
path: '*',
redirect: {
2020-01-14 21:01:24 +00:00
name: 'login'
2019-12-21 07:20:25 +00:00
}
2020-01-14 21:01:24 +00:00
}
2019-12-20 13:01:36 +00:00
]
const router = new VueRouter({
2019-12-21 07:20:25 +00:00
mode: 'history',
base: process.env.BASE_URL,
2019-12-20 13:01:36 +00:00
routes
})
2019-12-21 07:20:25 +00:00
router.beforeEach((to, from, next) => {
2020-01-14 21:01:24 +00:00
store.dispatch('fetchAccessToken')
let sites = ['/finanzer', '/bar']
if (sites.includes(to.fullPath)) {
if (to.fullPath === '/finanzer') {
if (!store.state.login.user.group.includes('moneymaster')) {
next('/login')
}
}
if (to.fullPath === '/bar') {
if (!store.state.login.user.group.includes('bar')) {
next('/login')
}
}
if (!store.state.login.user.accessToken) {
2019-12-21 07:20:25 +00:00
next('/login')
}
}
if (to.fullPath === '/login') {
if (store.state.login.user.accessToken) {
if (store.state.login.user.group.includes('moneymaster')) {
next('/finanzer')
} else if (store.state.login.user.group.includes('bar')) {
next('/bar')
}
2019-12-21 07:20:25 +00:00
}
}
2020-01-14 21:01:24 +00:00
next()
})
2019-12-21 07:20:25 +00:00
2019-12-20 13:01:36 +00:00
export default router