fix: prevent infinite refresh loops by checking URL in auth interceptor error handler

This commit is contained in:
Your Name
2026-04-10 18:40:46 +05:30
parent a0eec02ee4
commit c15a8b481b
+6 -3
View File
@@ -1,4 +1,4 @@
import axios from "axios";
import axios, { type AxiosError } from "axios";
const authApiClient = axios.create({
baseURL: `${import.meta.env.VITE_API_URL}/api/auth/`,
@@ -10,8 +10,11 @@ const authApiClient = axios.create({
authApiClient.interceptors.response.use(
(response) => response,
async (error) => {
if (error.response.status === 401) {
async (error: AxiosError) => {
if (
error.response.status === 401 &&
!error.config.url?.includes("refresh/")
) {
// token expired, refresh it
try {
const response = await authApiClient.post("refresh/");