flaschengeist-frontend/src/router/index.js

74 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'
2019-12-21 07:20:25 +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 = [
2019-12-21 07:20:25 +00:00
2019-12-20 13:01:36 +00:00
{
2019-12-21 07:20:25 +00:00
path: "/login",
name: "login",
component: Login
2019-12-20 13:01:36 +00:00
},
{
2019-12-21 07:20:25 +00:00
path: "/finanzer",
name: "finanzer",
component: FinanzerView
},
{
path: "/bar",
name: "bar",
component: BarView
},
{
path: '*',
redirect: {
name: "login"
}
},
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) => {
store.dispatch('fetchAccessToken');
let sites = ['/finanzer', '/bar']
if (sites.includes(to.fullPath)) {
if (to.fullPath === '/finanzer') {
if (!store.state.user.group.includes('moneymaster')) {
next('/login')
}
}
if (to.fullPath === '/bar') {
if (!store.state.user.group.includes('bar')) {
next('/login')
}
}
2019-12-21 07:20:25 +00:00
if (!store.state.user.accessToken) {
next('/login')
}
}
if (to.fullPath === '/login') {
if (store.state.user.accessToken) {
if (store.state.user.group.includes('moneymaster')) {
next('/finanzer')
} else if (store.state.user.group.includes('bar')) {
next('/bar')
}
2019-12-21 07:20:25 +00:00
}
}
next();
});
2019-12-20 13:01:36 +00:00
export default router