Derick Montague | a2988f4 | 2020-01-17 13:46:30 -0600 | [diff] [blame] | 1 | import Vue from "vue"; |
| 2 | import VueRouter from "vue-router"; |
Derick Montague | e080a1a | 2019-12-04 16:30:08 -0600 | [diff] [blame] | 3 | import store from "../store/index"; |
| 4 | import AppLayout from "../layouts/AppLayout.vue"; |
Derick Montague | a2988f4 | 2020-01-17 13:46:30 -0600 | [diff] [blame] | 5 | |
| 6 | Vue.use(VueRouter); |
| 7 | |
| 8 | const routes = [ |
| 9 | { |
| 10 | path: "/", |
Derick Montague | e080a1a | 2019-12-04 16:30:08 -0600 | [diff] [blame] | 11 | name: "", |
| 12 | meta: { |
| 13 | requiresAuth: true |
| 14 | }, |
| 15 | component: AppLayout, |
| 16 | children: [ |
| 17 | { |
| 18 | path: "", |
| 19 | component: () => import("@/views/Overview") |
| 20 | }, |
| 21 | { |
| 22 | path: "/access-control/local-user-management", |
| 23 | name: "local-users", |
| 24 | component: () => import("@/views/AccessControl/LocalUserManagement") |
| 25 | } |
| 26 | ] |
Derick Montague | a2988f4 | 2020-01-17 13:46:30 -0600 | [diff] [blame] | 27 | }, |
| 28 | { |
Derick Montague | e080a1a | 2019-12-04 16:30:08 -0600 | [diff] [blame] | 29 | path: "/login", |
| 30 | name: "login", |
| 31 | component: () => import("@/views/Login") |
Derick Montague | a2988f4 | 2020-01-17 13:46:30 -0600 | [diff] [blame] | 32 | } |
Derick Montague | a2988f4 | 2020-01-17 13:46:30 -0600 | [diff] [blame] | 33 | ]; |
| 34 | |
| 35 | const router = new VueRouter({ |
| 36 | mode: "history", |
| 37 | base: process.env.BASE_URL, |
| 38 | routes, |
| 39 | linkExactActiveClass: "nav__link--current" |
| 40 | }); |
| 41 | |
Derick Montague | e080a1a | 2019-12-04 16:30:08 -0600 | [diff] [blame] | 42 | router.beforeEach((to, from, next) => { |
| 43 | if (to.matched.some(record => record.meta.requiresAuth)) { |
| 44 | if (store.getters["authentication/isLoggedIn"]) { |
| 45 | next(); |
| 46 | return; |
| 47 | } |
| 48 | next("/login"); |
| 49 | } else { |
| 50 | next(); |
| 51 | } |
| 52 | }); |
| 53 | |
Derick Montague | a2988f4 | 2020-01-17 13:46:30 -0600 | [diff] [blame] | 54 | export default router; |