flaschengeist-frontend/src/router/index.js

74 lines
1.4 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 BarView from "@/views/BarView";
Vue.use(VueRouter)
const routes = [
{
path: "/login",
name: "login",
component: Login
},
{
path: "/finanzer",
name: "finanzer",
component: FinanzerView
},
{
path: "/bar",
name: "bar",
component: BarView
},
{
path: '*',
redirect: {
name: "login"
}
},
]
const router = new VueRouter({
mode: 'history',
base: process.env.BASE_URL,
routes
})
router.beforeEach((to, from, next) => {
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) {
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')
}
}
}
next();
});
export default router