-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathindex.js
More file actions
174 lines (166 loc) · 4.04 KB
/
index.js
File metadata and controls
174 lines (166 loc) · 4.04 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import Vue from 'vue';
import VueRouter from 'vue-router';
import Home from '../views/Home.vue';
import SignUp from '../views/auth/SignUp.vue';
import SignIn from '../views/auth/SignIn.vue';
import ForgotPassword from '../views/auth/ForgotPassword.vue';
import AccountVerified from '../views/auth/AccountVerified.vue';
import AccountVerifiedError from '../views/auth/AccountVerifiedError.vue';
import ResetPassword from '../views/auth/ResetPassword.vue';
import ResetPasswordError from '../views/auth/ResetPasswordError.vue';
import Onboarding from '../views/app/Onboarding.vue';
import Browse from '../views/app/Browse.vue';
import Search from '../views/app/Search.vue';
import Settings from '../views/app/Settings.vue';
import User from '../components/app/users/User.vue';
import History from '../views/app/History.vue';
import Matches from '../views/app/Matches.vue';
import SignOut from '../views/auth/SignOut.vue';
import NotFound from '../views/NotFound.vue';
import store from '../store/index';
Vue.use(VueRouter);
function loggedInRedirectBrowse(to, from, next) {
if (store.getters.getLoggedInUser) {
next('/browse');
} else {
next();
}
}
function loggedInAndProfileCompleted(to, from, next) {
const loggedInUser = store.getters.getLoggedInUser;
if (loggedInUser) {
if (loggedInUser.is_profile_completed) {
next();
} else {
next('/onboarding');
}
} else {
next('/accounts/signin');
}
}
function notLoggedInRedirectLogin(to, from, next) {
if (store.getters.getLoggedInUser) {
next();
} else {
next('/accounts/signin');
}
}
function blockRepeatedOnboarding(to, from, next) {
const user = store.getters.getLoggedInUser;
if (user && user.is_profile_completed) {
next('/browse');
} else if (user && !user.is_profile_completed) {
next();
} else {
next('/accounts/signin');
}
}
const routes = [
{
path: '/',
name: 'Home',
component: Home,
},
{
path: '/accounts/signup',
name: 'SignUp',
component: SignUp,
beforeEnter: loggedInRedirectBrowse,
},
{
path: '/accounts/signin',
name: 'SignIn',
component: SignIn,
beforeEnter: loggedInRedirectBrowse,
},
{
path: '/accounts/password/forgot',
name: 'ForgotPassword',
component: ForgotPassword,
beforeEnter: loggedInRedirectBrowse,
},
{
path: '/accounts/password/reset',
name: 'ResetPassword',
component: ResetPassword,
beforeEnter: loggedInRedirectBrowse,
},
{
path: '/accounts/password/reseterror',
name: 'ResetPasswordError',
component: ResetPasswordError,
beforeEnter: loggedInRedirectBrowse,
},
{
path: '/accounts/verify',
name: 'AccountVerified',
component: AccountVerified,
beforeEnter: loggedInRedirectBrowse,
},
{
path: '/accounts/verify/error',
name: 'AccountVerifiedError',
component: AccountVerifiedError,
beforeEnter: loggedInRedirectBrowse,
},
{
path: '/onboarding',
name: 'Onboarding',
component: Onboarding,
beforeEnter: blockRepeatedOnboarding,
},
{
path: '/browse',
name: 'Browse',
component: Browse,
beforeEnter: loggedInAndProfileCompleted,
props: true,
},
{
path: '/search',
component: Search,
name: 'Search',
beforeEnter: loggedInAndProfileCompleted,
},
{
path: '/settings',
component: Settings,
name: 'Settings',
beforeEnter: loggedInAndProfileCompleted,
},
{
path: '/users/:id',
component: User,
name: 'Users',
beforeEnter: loggedInAndProfileCompleted,
},
{
path: '/history',
component: History,
name: 'History',
beforeEnter: loggedInAndProfileCompleted,
},
{
path: '/matches',
component: Matches,
name: 'Matches',
beforeEnter: loggedInAndProfileCompleted,
},
{
path: '/accounts/signout',
component: SignOut,
name: 'SignOut',
beforeEnter: notLoggedInRedirectLogin,
},
{
path: '*',
component: NotFound,
name: 'NotFound',
},
];
const router = new VueRouter({
mode: 'history',
base: process.env.BASE_URL,
routes,
});
export default router;