From a69593a9e8432f595a59cbbd3c07101eae5cb0e9 Mon Sep 17 00:00:00 2001 From: guru_sainath Date: Fri, 5 May 2023 18:01:58 +0530 Subject: [PATCH] fix: handled token expiry validation (#1016) --- apps/app/services/api.service.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/apps/app/services/api.service.ts b/apps/app/services/api.service.ts index a625c0b37a..9582050058 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 = {};