This repository has been archived by the owner on Jul 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrouter.ts
78 lines (75 loc) · 1.77 KB
/
router.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import { createRouter, createWebHistory } from 'vue-router';
import { routeGuard } from '../src';
import Home from './components/Home.vue';
import Login from './components/Login.vue';
import ManageAccessKeys from './components/ManageAccessKeys.vue';
import ManageAudit from './components/ManageAudit.vue';
import ManageRoles from './components/ManageRoles.vue';
import ManageUsers from './components/ManageUsers.vue';
import MyUserProfile from './components/MyUserProfile.vue';
const router = createRouter({
history: createWebHistory(),
routes: [
{
path: '/',
name: 'home',
component: Home,
meta: {
requiresAuth: true
}
// Alternative method to guard route implemented in the beforeEach bellow:
/*
beforeEnter: async (to, from, next) => {
// alternative method to guard route
const isAuthenticated = await routeGuard();
if (!isAuthenticated) {
next({ name: 'login' });
} else {
next();
}
}
*/
// alternative method to guard route implemented in the beforeEach bellow:
// beforeEnter: routeGuard
},
{
path: '/login',
name: 'login',
component: Login
},
{
path: '/manage-users',
name: 'manage-users',
component: ManageUsers
},
{
path: '/manage-roles',
name: 'manage-roles',
component: ManageRoles
},
{
path: '/manage-access-keys',
name: 'manage-access-keys',
component: ManageAccessKeys
},
{
path: '/manage-audit',
name: 'manage-audit',
component: ManageAudit
},
{
path: '/user-profile',
name: 'user-profile',
component: MyUserProfile
}
]
});
router.beforeEach(async (to, from, next) => {
const isAuthenticated = await routeGuard();
if (to.meta.requiresAuth && !isAuthenticated) {
next({ name: 'login' });
} else {
next();
}
});
export default router;