From ac119932fc986be6262bcda612f1de2a46e5e55d Mon Sep 17 00:00:00 2001 From: a-honey Date: Wed, 28 Feb 2024 05:04:05 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EB=A6=AC=ED=94=84=EB=A0=88=EC=8B=9C=20?= =?UTF-8?q?=ED=86=A0=ED=81=B0=EC=9C=BC=EB=A1=9C=20=EC=97=91=EC=84=B8?= =?UTF-8?q?=EC=8A=A4=20=ED=86=A0=ED=81=B0=20=EB=B0=9B=EC=95=84=EC=98=A4?= =?UTF-8?q?=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit cors 에러 추정 --- src/api/axiosInstance.ts | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/api/axiosInstance.ts b/src/api/axiosInstance.ts index f1798bd..376f605 100644 --- a/src/api/axiosInstance.ts +++ b/src/api/axiosInstance.ts @@ -27,7 +27,6 @@ axiosInstance.interceptors.response.use( const originalRequest = error.config; if (error.response?.status === 401 && !originalRequest._retry) { - /* originalRequest._retry = true; const refreshToken = @@ -36,22 +35,21 @@ axiosInstance.interceptors.response.use( : null; try { - const refreshResponse = await axios.post('/users/kakao-login', { - refreshToken, - }); - - if (typeof window !== 'undefined') { - localStorage.setItem('accessToken', refreshResponse.data.accessToken); + originalRequest.headers['Refresh-Token'] = refreshToken; + const res = await axiosInstance(originalRequest); + const newAccessToken = res.headers['new-access-token']; + if (newAccessToken) { + localStorage.setItem('accessToken', newAccessToken); } - originalRequest.headers.Authorization = `Bearer ${refreshResponse.data.accessToken}`; + originalRequest.headers.Authorization = `Bearer ${newAccessToken}`; return await axiosInstance(originalRequest); } catch (refreshError) { console.error('Error refreshing token:', refreshError); throw refreshError; } - */ - window.location.href = '/login'; + + // window.location.href = '/login'; } return await Promise.reject(error);