-
Notifications
You must be signed in to change notification settings - Fork 11
/
index.ts
62 lines (56 loc) · 1.29 KB
/
index.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
import { Router, createRouter, createWebHistory } from 'vue-router';
import Login from '@/containers/Login.vue';
import Dashboard from '@/containers/Dashboard.vue';
import Page404 from '@/containers/404.vue';
import Policy from '@/containers/Policy.vue';
import Analytics from '@/containers/Analytics.vue';
import store from '../store';
const router: Router = createRouter({
history: createWebHistory(),
routes: [
{
path: '/login',
name: 'Login',
component: Login,
},
{
path: '/',
name: 'Dashboard',
component: Dashboard,
meta: {
requiresAuth: true,
},
},
{
path: '/policy',
name: 'Policy',
component: Policy,
},
{
path: '/analytics',
name: 'Analytics',
component: Analytics,
meta: {
requiresAuth: true,
},
},
{
path: '/:pathMatch(.*)*',
name: '404',
component: Page404,
},
],
});
router.beforeEach((to, from, next) => {
const { matched } = to;
const requiresAuth = matched.some(x => x.meta.requiresAuth);
const { currentFirebaseUser } = store.state;
if (requiresAuth && !currentFirebaseUser) {
next('/login');
} else if (requiresAuth && currentFirebaseUser) {
next();
} else {
next();
}
});
export default router;