restructure api request
This commit is contained in:
@@ -393,7 +393,9 @@ router.beforeEach(async (to, from, next) => {
|
|||||||
if (to.meta.middleware == "authenticated") {
|
if (to.meta.middleware == "authenticated") {
|
||||||
if (userStore.id) {
|
if (userStore.id) {
|
||||||
try {
|
try {
|
||||||
let res = await api.get("/me");
|
let res = await api.get({
|
||||||
|
url: "/me",
|
||||||
|
});
|
||||||
userStore.setUserDetails(res.json.user);
|
userStore.setUserDetails(res.json.user);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err.status == 401) {
|
if (err.status == 401) {
|
||||||
@@ -407,12 +409,22 @@ router.beforeEach(async (to, from, next) => {
|
|||||||
name: "login",
|
name: "login",
|
||||||
query: { redirect: encodeURIComponent(to.fullPath) },
|
query: { redirect: encodeURIComponent(to.fullPath) },
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
next();
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
next();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
api.post({
|
||||||
|
url: "/analytics",
|
||||||
|
body: {
|
||||||
|
type: "pageview",
|
||||||
|
attribute: to.fullPath,
|
||||||
|
},
|
||||||
|
}).catch(() => {
|
||||||
|
/* empty */
|
||||||
|
});
|
||||||
|
|
||||||
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
router.afterEach((to, from) => {
|
router.afterEach((to, from) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user