From 0ee4fe6726b7637a46ec27cee78b5220c780f2c2 Mon Sep 17 00:00:00 2001 From: 2paperstar Date: Fri, 7 Jun 2024 05:03:19 +0900 Subject: [PATCH] fix: refresh token infinite try error --- src/api/index.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/api/index.ts b/src/api/index.ts index a233614..04b9e64 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -16,7 +16,12 @@ api.interceptors.response.use( (response) => response, async (error) => { const originalRequest = error.config; - if (error.response?.status === 401 && !originalRequest._retry) { + if (error.response?.status === 401) { + if (originalRequest._retry || originalRequest.url === '/auth/refresh') { + localStorage.removeItem('accessToken'); + localStorage.removeItem('refreshToken'); + return Promise.reject(error); + } originalRequest._retry = true; const refreshToken = localStorage.getItem('refreshToken'); if (!refreshToken) {