fix: handled token expiry validation (#1016)

This commit is contained in:
guru_sainath 2023-05-05 18:01:58 +05:30 committed by GitHub
parent a1de3f581f
commit a69593a9e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 = {};