flaschengeist-frontend/src/router/index.js

131 lines
3.2 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'
2020-01-17 00:01:10 +00:00
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'
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
},
2019-12-21 07:20:25 +00:00
{
2020-01-17 00:01:10 +00:00
path: '/main',
name: 'main',
component: MainView,
children: [
{
path: 'user',
name: 'user',
components: { userNav: UserNavigation, default: UserView },
2020-01-17 00:01:10 +00:00
children: [
{
path: 'add',
name: 'add',
component: AddAmount
},
{
path: 'overview',
name: 'userOverview',
component: CreditOverview
}
]
},
{
path: 'bar',
name: 'bar',
components: { userNav: BarNavigation, default: BarView },
2020-01-17 00:01:10 +00:00
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
}
]
2020-01-17 00:01:10 +00:00
}
]
2019-12-21 07:20:25 +00:00
},
{
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')
2020-01-17 00:01:10 +00:00
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')
}
}
2020-01-17 00:01:10 +00:00
if (to.fullPath.includes('/main/bar')) {
if (!store.state.login.user.group.includes('bar')) {
next('/login')
}
}
2020-01-17 00:01:10 +00:00
if (to.fullPath.includes('/main/user')) {
if (!store.state.login.user.group.includes('user')) {
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')) {
2020-01-17 00:01:10 +00:00
next('/main/finanzer')
} else if (store.state.login.user.group.includes('bar')) {
2020-01-17 00:01:10 +00:00
next('/main/bar/geruecht')
} else if (store.state.login.user.group.includes('user')) {
next('/main/user/add')
}
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