fixed expiring login creds
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import axios, { type AxiosRequestConfig } from "axios";
|
||||
import { AUTH_FLAG } from "@/context/AuthContext";
|
||||
import { AUTH_FLAG } from "@/hooks/useAuth";
|
||||
|
||||
export const privateApi = axios.create({
|
||||
withCredentials: true,
|
||||
@@ -38,7 +38,7 @@ privateApi.interceptors.response.use(
|
||||
}
|
||||
}
|
||||
|
||||
if (error.response?.status === 401 && !original._retry) {
|
||||
if ((error.response?.status === 401 || error.response?.status === 403) && !original._retry) {
|
||||
if (original.url?.includes("/api/account/logout/")) {
|
||||
return Promise.reject(error);
|
||||
}
|
||||
@@ -79,8 +79,11 @@ privateApi.interceptors.response.use(
|
||||
await privateApi.post("/api/account/token/refresh/");
|
||||
processQueue();
|
||||
return privateApi(original);
|
||||
} catch (refreshError) {
|
||||
} catch (refreshError: any) {
|
||||
processQueue(refreshError);
|
||||
// Refresh failed for any reason (400 missing cookie, 401 expired) — clear auth and redirect
|
||||
localStorage.removeItem(AUTH_FLAG);
|
||||
window.location.href = "/social/login";
|
||||
return Promise.reject(refreshError);
|
||||
} finally {
|
||||
isRefreshing = false;
|
||||
|
||||
Reference in New Issue
Block a user