Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 0 additions & 94 deletions src/apis/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,6 @@ api.interceptors.request.use(
(config) => {
const accessToken = getAccessToken();

console.log('========== API REQUEST ==========');
console.log('[REQUEST] method:', config.method);
console.log('[REQUEST] url:', config.url);
console.log(
'[REQUEST] baseURL:',
config.baseURL,
);
console.log(
'[REQUEST] withCredentials:',
config.withCredentials,
);

if (accessToken) {
config.headers.Authorization =
/^Bearer\s+/i.test(accessToken)
Expand All @@ -46,51 +34,21 @@ api.interceptors.request.use(
return config;
},
(error: AxiosError) => {
console.error(
'[REQUEST INTERCEPTOR ERROR]',
error,
);

return Promise.reject(error);
},
);

api.interceptors.response.use(
(response) => {
console.log('========== API RESPONSE ==========');
console.log('[RESPONSE] url:', response.config.url);
console.log('[RESPONSE] status:', response.status);

return response;
},
async (error: AxiosError) => {
console.error('========== API ERROR ==========');
console.error(
'[ERROR] status:',
error.response?.status,
);
console.error(
'[ERROR] url:',
error.config?.url,
);
console.error(
'[ERROR] method:',
error.config?.method,
);
console.error(
'[ERROR] message:',
error.message,
);

const originalRequest = error.config as
| RetryRequestConfig
| undefined;

if (!originalRequest) {
console.error(
'[INTERCEPTOR] 기존 요청 정보가 없습니다.',
);

return Promise.reject(error);
}

Expand All @@ -115,52 +73,21 @@ api.interceptors.response.use(
originalRequest.url?.includes(url),
);

console.log(
'========== INTERCEPTOR CHECK ==========',
);
console.log(
'[INTERCEPTOR] 401 여부:',
isUnauthorized,
);
console.log(
'[INTERCEPTOR] 제외 API 여부:',
isExcludedRequest,
);
console.log(
'[INTERCEPTOR] 이미 재시도했는지:',
Boolean(originalRequest._retry),
);

if (
!isUnauthorized ||
originalRequest._retry ||
isExcludedRequest
) {
console.log(
'[INTERCEPTOR] 재발급을 시도하지 않습니다.',
);

return Promise.reject(error);
}

originalRequest._retry = true;

console.log(
'[INTERCEPTOR] Access Token 재발급 시작',
);

try {
const newAccessToken =
await reissueAccessToken();

console.log(
'[INTERCEPTOR] Access Token 재발급 성공',
);
console.log(
'[INTERCEPTOR] 기존 요청 재시도:',
originalRequest.url,
);

originalRequest.headers =
originalRequest.headers ?? {};

Expand All @@ -169,30 +96,9 @@ api.interceptors.response.use(

return api(originalRequest);
} catch (reissueError) {
const axiosError =
reissueError as AxiosError;

console.error(
'========== REISSUE FINAL ERROR ==========',
);
console.error(
'[INTERCEPTOR] 재발급 실패 status:',
axiosError.response?.status,
);
console.error(
'[INTERCEPTOR] 재발급 실패 message:',
axiosError.message,
);

clearAuthData();

console.log(
'[INTERCEPTOR] 인증 데이터 삭제 완료',
);

// 디버깅 중에는 페이지 이동을 막아두는 게 좋음
// window.location.replace('/login');

return Promise.reject(reissueError);
}
},
Expand Down
21 changes: 2 additions & 19 deletions src/apis/token.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import axios, { AxiosError } from 'axios';
import axios from 'axios';

interface ApiResponse<T> {
isSuccess: boolean;
Expand Down Expand Up @@ -40,37 +40,20 @@ export const clearAuthData = (): void => {
};

export const reissueAccessToken = async (): Promise<string> => {
console.log('========== ACCESS TOKEN REISSUE ==========');
console.log('[REISSUE] API URL :', import.meta.env.VITE_API_URL);
console.log('[REISSUE] 요청 시작');

try {

const response = await refreshApi.post<ApiResponse<ReissueResult>>(
'/api/auth/reissue',
);

console.log('[REISSUE] 응답 상태 :', response.status);

const newAccessToken = response.data.result.accessToken;

if (!newAccessToken) {
console.error('[REISSUE] Access Token 없음');
throw new Error('재발급 응답에 Access Token이 없습니다.');
}


setAccessToken(newAccessToken);

console.log('[REISSUE] LocalStorage 저장 완료');

return newAccessToken;
} catch (error) {
const axiosError = error as AxiosError;

console.error('========== REISSUE ERROR ==========');
console.error('Status :', axiosError.response?.status);
console.error('Message :', axiosError.message);

throw error;
}
};
4 changes: 2 additions & 2 deletions src/pages/my-page/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ const MyPage = () => {
clearAuthData();
closeModal();
navigate('/login', { replace: true });
} catch (error) {
console.error('회원탈퇴 실패:', error);
} catch {
alert('회원탈퇴에 실패했습니다. 다시 시도해주세요.',);
}
};

Expand Down
4 changes: 1 addition & 3 deletions src/pages/my-page/profile-edit-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,7 @@ const ProfileEditForm = ({
});
},

onError: (error) => {
console.error('프로필 수정 실패:', error);

onError: () => {
alert(
'프로필 수정에 실패했습니다. 다시 시도해주세요.',
);
Expand Down
12 changes: 2 additions & 10 deletions src/pages/signup/profile-create-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -295,11 +295,7 @@ const ProfileCreatePage = () => {
await uploadProfileImage(
profileImageFile,
);
} catch (error) {
console.error(
'프로필 이미지 업로드 실패:',
error,
);
} catch {

alert(
'프로필은 생성되었지만 이미지 업로드에 실패했습니다. 마이페이지에서 다시 등록해주세요.',
Expand All @@ -315,11 +311,7 @@ const ProfileCreatePage = () => {
navigate('/signup/complete', {
replace: true,
});
} catch (error) {
console.error(
'프로필 생성 실패:',
error,
);
} catch {

alert(
'프로필 생성에 실패했습니다. 다시 시도해주세요.',
Expand Down
6 changes: 2 additions & 4 deletions src/pages/signup/terms-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ if (
}, {});

setAgreements(initialAgreements);
} catch (error) {
console.error('약관 조회 실패:', error);
} catch {

setLoadErrorMessage('약관을 불러오지 못했습니다.');
} finally {
Expand Down Expand Up @@ -201,8 +200,7 @@ if (
navigate('/signup/profile', {
replace: true,
});
} catch (error) {
console.error('소셜 회원가입 실패:', error);
} catch {

setSubmitErrorMessage('회원가입 중 오류가 발생했습니다.');
} finally {
Expand Down
Loading