blob: 3f447de3180de1bd2f55130aa62c1158a1179d89 [file] [log] [blame]
Derick Montaguefded0d12019-12-11 06:16:40 -06001import Vue from 'vue';
2import VueRouter from 'vue-router';
Yoshie Muranaka8263d852020-10-16 07:58:06 -07003
4//Do not change store or routes import.
5//Exact match alias set to support
6//dotenv customizations.
Yoshie Muranaka8263d852020-10-16 07:58:06 -07007import store from '../store';
Dixsie Wolmers0a5b9c62020-10-20 10:52:56 -05008import routes from './routes';
Derick Montaguea2988f42020-01-17 13:46:30 -06009
10Vue.use(VueRouter);
11
Derick Montaguea2988f42020-01-17 13:46:30 -060012const router = new VueRouter({
Derick Montaguea2988f42020-01-17 13:46:30 -060013 base: process.env.BASE_URL,
14 routes,
Yoshie Muranaka71ac2302019-12-26 11:43:36 -080015 linkExactActiveClass: 'nav-link--current'
Derick Montaguea2988f42020-01-17 13:46:30 -060016});
17
Derick Montaguee080a1a2019-12-04 16:30:08 -060018router.beforeEach((to, from, next) => {
19 if (to.matched.some(record => record.meta.requiresAuth)) {
Derick Montaguefded0d12019-12-11 06:16:40 -060020 if (store.getters['authentication/isLoggedIn']) {
Derick Montaguee080a1a2019-12-04 16:30:08 -060021 next();
22 return;
23 }
Derick Montaguefded0d12019-12-11 06:16:40 -060024 next('/login');
Derick Montaguee080a1a2019-12-04 16:30:08 -060025 } else {
26 next();
27 }
28});
29
Derick Montaguea2988f42020-01-17 13:46:30 -060030export default router;