Skip to content

Commit

Permalink
feat: 리프레시 토큰으로 엑세스 토큰 받아오기
Browse files Browse the repository at this point in the history
cors 에러 추정
  • Loading branch information
a-honey committed Feb 27, 2024
1 parent c7b0d26 commit ac11993
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/api/axiosInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ axiosInstance.interceptors.response.use(
const originalRequest = error.config;

if (error.response?.status === 401 && !originalRequest._retry) {
/*
originalRequest._retry = true;

const refreshToken =
Expand All @@ -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);
Expand Down

0 comments on commit ac11993

Please sign in to comment.