diff --git a/apps/app/services/api.service.ts b/apps/app/services/api.service.ts index a625c0b37..958205005 100644 --- a/apps/app/services/api.service.ts +++ b/apps/app/services/api.service.ts @@ -1,6 +1,21 @@ import axios from "axios"; import Cookies from "js-cookie"; +const unAuthorizedStatus = [401]; +axios.interceptors.response.use( + (response) => response, + (error) => { + const { status }: any = error.response; + if (unAuthorizedStatus.includes(status)) { + Cookies.remove("refreshToken", { path: "/" }); + Cookies.remove("accessToken", { path: "/" }); + console.log("window.location.href", window.location.pathname); + if (window.location.pathname != "/signin") window.location.href = "/signin"; + } + return Promise.reject(error); + } +); + abstract class APIService { protected baseURL: string; protected headers: any = {};