Skip to content

Commit

Permalink
OC-249
Browse files Browse the repository at this point in the history
  • Loading branch information
Vadimus committed Sep 11, 2023
1 parent 7eab2a7 commit 766e7af
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
26 changes: 15 additions & 11 deletions src/plugins/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,26 +88,30 @@ export default (app) => {
error.response?.data?.code?.code === "token_not_valid"
) {
const originalRequest = error.config;
await store.dispatch("core/refreshToken");
originalRequest.headers["Authorization"] =
"Bearer " + localStorage.getItem("token");
return app.config.globalProperties.$http(originalRequest);
try {
await store.dispatch("core/refreshToken");
originalRequest.headers["Authorization"] =
"Bearer " + localStorage.getItem("token");
return app.config.globalProperties.$http(originalRequest);
} catch (e) {
console.log(e);
}
}
const pathname = window.location.pathname;
const matchNotAuthViews = noAuthRequireRoutes.find((route) =>
pathname.startsWith(route)
);
if (pathname !== "/" && !matchNotAuthViews) {
const lastPage = router.currentRoute.value.fullPath;
if (lastPage) {
if (
error.response &&
error.response?.data?.code?.code !== "token_not_valid"
) {
if (
error.response &&
error.response?.data?.code?.code === "token_not_valid"
) {
if (lastPage) {
router.push({ name: "login", query: { redirectFrom: lastPage } });
} else {
router.push({ name: "login" });
}
} else {
router.push({ name: "login" });
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/store/core/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,9 @@ export default {
localStorage.setItem("token", response.data.access);
localStorage.setItem("refresh_token", response.data.refresh);
})
.catch(() => {
.catch((e) => {
dispatch("logout");
return Promise.reject(e);
})
.finally(() => {
refreshTokenPromise = null;
Expand Down

0 comments on commit 766e7af

Please sign in to comment.