-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.ts
44 lines (40 loc) · 1.06 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
import {GOLINK_PATTERN} from "../src/shared";
export const state = () => ({
flags: {},
linkItem: null,
user: null,
userId: null,
});
export const mutations = {
setUser(state, user) {
state.user = user;
},
setUserId(state, userId) {
state.userId = userId;
},
setLinkItem (state, linkItem) {
state.linkItem = linkItem;
},
};
export const actions = {
async nuxtServerInit({ commit, state, }, ctx2) {
if (['/edit','/dashboard'].indexOf(ctx2.route.path) >= 0) {
return;
} // TODO(xinbenlv@): This is pretty buggy, we shall find better solution
let goLink = ctx2.params.goLink;
if (goLink && new RegExp(GOLINK_PATTERN).test(goLink)) {
let linkItems = await this.$axios.$get(`/api/v2/link/${goLink}`);
if (linkItems.length == 1) {
commit('setLinkItem', linkItems[0]);
} else {
ctx2.redirect(`/edit/${goLink}`);
}
} else {
ctx2.redirect(`/edit`);
}
if(ctx2.req.user) {
commit('setUser', ctx2.req.user);
commit('setUserId', ctx2.req.user.emails[0].value)
}
}
};