flaschengeist-frontend/src/router/index.js

131 lines
3.2 KiB
JavaScript

import Vue from 'vue'
import VueRouter from 'vue-router'
import FinanzerView from '@/views/FinanzerView'
import Login from '@/views/Login'
import store from '@/store/index'
import GeruechteView from '../views/contents/GeruechteView'
import AddAmount from '../components/user/AddAmount'
import CreditOverview from '../components/user/CreditOverview'
import MainView from '../views/MainView'
import UserView from '../views/UserView'
import BarView from '../views/BarView'
import UserNavigation from '../components/user/UserNavigation'
import BarNavigation from '../components/baruser/BarNavigation'
import FinanzerNavigation from '../components/finanzer/FinanzerNavigation'
import Overview from '../components/finanzer/Overview'
import User from '../components/finanzer/User'
Vue.use(VueRouter)
const routes = [
{
path: '/login',
name: 'login',
component: Login
},
{
path: '/main',
name: 'main',
component: MainView,
children: [
{
path: 'user',
name: 'user',
components: { userNav: UserNavigation, default: UserView },
children: [
{
path: 'add',
name: 'add',
component: AddAmount
},
{
path: 'overview',
name: 'userOverview',
component: CreditOverview
}
]
},
{
path: 'bar',
name: 'bar',
components: { userNav: BarNavigation, default: BarView },
children: [
{
path: 'geruecht',
name: 'geruecht',
component: GeruechteView
}
]
},
{
path: 'finanzer',
name: 'finanzer',
components: { default: FinanzerView, finanzerNav: FinanzerNavigation },
children: [
{
path: 'overview',
component: Overview
},
{
path: 'user/:id',
name: 'activeUser',
props: true,
component: User
}
]
}
]
},
{
path: '*',
redirect: {
name: 'login'
}
}
]
const router = new VueRouter({
mode: 'history',
base: process.env.BASE_URL,
routes
})
router.beforeEach((to, from, next) => {
store.dispatch('fetchAccessToken')
console.log('fullPath', to.fullPath)
if (to.fullPath.includes('/main')) {
if (to.fullPath.includes('/main/finanzer')) {
if (!store.state.login.user.group.includes('moneymaster')) {
next('/login')
}
}
if (to.fullPath.includes('/main/bar')) {
if (!store.state.login.user.group.includes('bar')) {
next('/login')
}
}
if (to.fullPath.includes('/main/user')) {
if (!store.state.login.user.group.includes('user')) {
next('/login')
}
}
if (!store.state.login.user.accessToken) {
next('/login')
}
}
if (to.fullPath === '/login') {
if (store.state.login.user.accessToken) {
if (store.state.login.user.group.includes('moneymaster')) {
next('/main/finanzer')
} else if (store.state.login.user.group.includes('bar')) {
next('/main/bar/geruecht')
} else if (store.state.login.user.group.includes('user')) {
next('/main/user/add')
}
}
}
next()
})
export default router