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' Vue.use(VueRouter) const routes = [ { path: '/login', name: 'login', component: Login }, { path: '/finanzer', name: 'finanzer', component: FinanzerView }, { path: '/main', name: 'main', component: MainView, children: [ { path: 'user', name: 'user', component: UserView, children: [ { path: 'add', name: 'add', component: AddAmount }, { path: 'overview', name: 'userOverview', component: CreditOverview } ] }, { path: 'bar', name: 'bar', component: BarView, children: [ { path: 'geruecht', name: 'geruecht', component: GeruechteView } ] }, { path: 'finanzer', name: 'finanzer', component: FinanzerView } ] }, { 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