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');
|
2019-12-26 09:31:36 +00:00
|
|
|
let sites = ['/finanzer', '/bar']
|
|
|
|
if (sites.includes(to.fullPath)) {
|
|
|
|
if (to.fullPath === '/finanzer') {
|
2020-01-05 22:39:30 +00:00
|
|
|
if (!store.state.login.user.group.includes('moneymaster')) {
|
2019-12-26 09:31:36 +00:00
|
|
|
next('/login')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (to.fullPath === '/bar') {
|
2020-01-05 22:39:30 +00:00
|
|
|
if (!store.state.login.user.group.includes('bar')) {
|
2019-12-26 09:31:36 +00:00
|
|
|
next('/login')
|
|
|
|
}
|
|
|
|
}
|
2020-01-05 22:39:30 +00:00
|
|
|
if (!store.state.login.user.accessToken) {
|
2019-12-21 07:20:25 +00:00
|
|
|
next('/login')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (to.fullPath === '/login') {
|
2020-01-05 22:39:30 +00:00
|
|
|
if (store.state.login.user.accessToken) {
|
|
|
|
if (store.state.login.user.group.includes('moneymaster')) {
|
2019-12-26 09:31:36 +00:00
|
|
|
next('/finanzer')
|
2020-01-05 22:39:30 +00:00
|
|
|
} else if (store.state.login.user.group.includes('bar')) {
|
2019-12-26 09:31:36 +00:00
|
|
|
next('/bar')
|
|
|
|
}
|
|
|
|
|
2019-12-21 07:20:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
next();
|
|
|
|
});
|
|
|
|
|
2019-12-20 13:01:36 +00:00
|
|
|
export default router
|