Skip to content

Commit 5b1b311

Browse files
committed
refactor: standalone router module
1 parent 177cd51 commit 5b1b311

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

auth/src/router.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import Vue from 'vue';
2+
import VueRouter from 'vue-router';
3+
4+
import store from './store';
5+
6+
import IndexPage from './pages/Index';
7+
import LoginPage from './pages/Login';
8+
9+
const router = new VueRouter({
10+
mode: 'history',
11+
routes: [
12+
{
13+
path: '/',
14+
name: 'index',
15+
component: IndexPage,
16+
},
17+
{
18+
path: '/login',
19+
name: 'login',
20+
component: LoginPage,
21+
},
22+
]
23+
});
24+
25+
/**
26+
* Navigation Guards
27+
* Redirect to login if the user is not authenticated
28+
*/
29+
router.beforeEach((to, from, next) => {
30+
if (to.name !== 'login' && !store.state.accessToken) {
31+
next('/login');
32+
}
33+
next();
34+
});
35+
36+
Vue.use(VueRouter);
37+
38+
export default router;

0 commit comments

Comments
 (0)