Skip to content

Commit

Permalink
fix: axios intercept 401 to relogin
Browse files Browse the repository at this point in the history
  • Loading branch information
whatwewant committed Jun 14, 2024
1 parent afb2432 commit e8ed485
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions web/src/helpers/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@ import { Resource } from "@/types/proto/api/v2/resource_service";
axios.defaults.baseURL = import.meta.env.VITE_API_BASE_URL || "";
axios.defaults.withCredentials = true;

let isRefreshing = false;
axios.interceptors.response.use(response => {
return response;
}, error => {
if (error.response.status === 401) {
if (isRefreshing) {
return;
}

isRefreshing = true;
window.location.reload();
return;
}

return Promise.reject(error);
});

export function getSystemStatus() {
return axios.get<SystemStatus>("/api/v1/status");
}
Expand Down

0 comments on commit e8ed485

Please sign in to comment.