Derick Montague | fded0d1 | 2019-12-11 06:16:40 -0600 | [diff] [blame^] | 1 | import Vue from 'vue'; |
| 2 | import VueRouter from 'vue-router'; |
| 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 | { |
Derick Montague | fded0d1 | 2019-12-11 06:16:40 -0600 | [diff] [blame^] | 10 | path: '/', |
| 11 | name: '', |
Derick Montague | e080a1a | 2019-12-04 16:30:08 -0600 | [diff] [blame] | 12 | meta: { |
| 13 | requiresAuth: true |
| 14 | }, |
| 15 | component: AppLayout, |
| 16 | children: [ |
| 17 | { |
Derick Montague | fded0d1 | 2019-12-11 06:16:40 -0600 | [diff] [blame^] | 18 | path: '', |
| 19 | component: () => import('@/views/Overview'), |
Derick Montague | c8636e5 | 2019-12-06 01:28:38 -0600 | [diff] [blame] | 20 | meta: { |
Derick Montague | fded0d1 | 2019-12-11 06:16:40 -0600 | [diff] [blame^] | 21 | title: 'Server Overview' |
Derick Montague | c8636e5 | 2019-12-06 01:28:38 -0600 | [diff] [blame] | 22 | } |
Derick Montague | e080a1a | 2019-12-04 16:30:08 -0600 | [diff] [blame] | 23 | }, |
| 24 | { |
Derick Montague | fded0d1 | 2019-12-11 06:16:40 -0600 | [diff] [blame^] | 25 | path: '/access-control/local-user-management', |
| 26 | name: 'local-users', |
| 27 | component: () => import('@/views/AccessControl/LocalUserManagement'), |
Derick Montague | c8636e5 | 2019-12-06 01:28:38 -0600 | [diff] [blame] | 28 | meta: { |
Derick Montague | fded0d1 | 2019-12-11 06:16:40 -0600 | [diff] [blame^] | 29 | title: 'Manage Local Users' |
Derick Montague | c8636e5 | 2019-12-06 01:28:38 -0600 | [diff] [blame] | 30 | } |
Derick Montague | e080a1a | 2019-12-04 16:30:08 -0600 | [diff] [blame] | 31 | } |
| 32 | ] |
Derick Montague | a2988f4 | 2020-01-17 13:46:30 -0600 | [diff] [blame] | 33 | }, |
| 34 | { |
Derick Montague | fded0d1 | 2019-12-11 06:16:40 -0600 | [diff] [blame^] | 35 | path: '/login', |
| 36 | name: 'login', |
| 37 | component: () => import('@/views/Login'), |
Derick Montague | c8636e5 | 2019-12-06 01:28:38 -0600 | [diff] [blame] | 38 | meta: { |
Derick Montague | fded0d1 | 2019-12-11 06:16:40 -0600 | [diff] [blame^] | 39 | title: 'Login' |
Derick Montague | c8636e5 | 2019-12-06 01:28:38 -0600 | [diff] [blame] | 40 | } |
Derick Montague | a2988f4 | 2020-01-17 13:46:30 -0600 | [diff] [blame] | 41 | } |
Derick Montague | a2988f4 | 2020-01-17 13:46:30 -0600 | [diff] [blame] | 42 | ]; |
| 43 | |
| 44 | const router = new VueRouter({ |
Derick Montague | a2988f4 | 2020-01-17 13:46:30 -0600 | [diff] [blame] | 45 | base: process.env.BASE_URL, |
| 46 | routes, |
Derick Montague | fded0d1 | 2019-12-11 06:16:40 -0600 | [diff] [blame^] | 47 | linkExactActiveClass: 'nav__link--current' |
Derick Montague | a2988f4 | 2020-01-17 13:46:30 -0600 | [diff] [blame] | 48 | }); |
| 49 | |
Derick Montague | e080a1a | 2019-12-04 16:30:08 -0600 | [diff] [blame] | 50 | router.beforeEach((to, from, next) => { |
| 51 | if (to.matched.some(record => record.meta.requiresAuth)) { |
Derick Montague | fded0d1 | 2019-12-11 06:16:40 -0600 | [diff] [blame^] | 52 | if (store.getters['authentication/isLoggedIn']) { |
Derick Montague | e080a1a | 2019-12-04 16:30:08 -0600 | [diff] [blame] | 53 | next(); |
| 54 | return; |
| 55 | } |
Derick Montague | fded0d1 | 2019-12-11 06:16:40 -0600 | [diff] [blame^] | 56 | next('/login'); |
Derick Montague | e080a1a | 2019-12-04 16:30:08 -0600 | [diff] [blame] | 57 | } else { |
| 58 | next(); |
| 59 | } |
| 60 | }); |
| 61 | |
Derick Montague | a2988f4 | 2020-01-17 13:46:30 -0600 | [diff] [blame] | 62 | export default router; |