로그인 — 자격증명 오류시 메시지 유지 및 LOGIN_FAILED 코드 처리

- /auth/login 401 응답은 인터셉터에서 리다이렉트하지 않고 그대로 반환해 호출부에서 에러 메시지를 표시하도록 수정
- apiCall에서 errorCode 추출 시 error.code 경로도 지원
- useLogin: errorCode === "LOGIN_FAILED"면 INVALID_CREDENTIALS 메시지 노출
This commit is contained in:
chpark
2026-05-14 16:30:11 +09:00
parent 430a511605
commit a5ddf852fc
2 changed files with 19 additions and 7 deletions
+7 -2
View File
@@ -150,8 +150,13 @@ export const useLogin = () => {
router.push(AUTH_CONFIG.ROUTES.MAIN);
}
} else {
// 로그인 실패
setError(result.message || FORM_VALIDATION.MESSAGES.LOGIN_FAILED);
// 로그인 실패: 백엔드 LOGIN_FAILED 코드면 자격증명 메시지로 안내
const isCredentialError = result.errorCode === "LOGIN_FAILED";
setError(
isCredentialError
? FORM_VALIDATION.MESSAGES.INVALID_CREDENTIALS
: result.message || FORM_VALIDATION.MESSAGES.LOGIN_FAILED,
);
console.error("로그인 실패:", result);
}
} catch (error) {
+12 -5
View File
@@ -410,6 +410,13 @@ apiClient.interceptors.response.use(
authLog("API_401_RECEIVED", `URL: ${url} | 코드: ${errorCode || "없음"} | 상세: ${errorDetails || "없음"}`);
// 로그인 요청 자체에서 발생한 401(아이디/비밀번호 오류 등)은
// 호출부에서 에러 메시지를 화면에 표시할 수 있도록 그대로 반환한다.
// 여기서 redirectToLogin()을 호출하면 페이지가 새로고침되어 에러가 사라진다.
if (url?.includes("/auth/login")) {
return Promise.reject(error);
}
// 이미 재시도한 요청이면 로그인으로
if (originalRequest?._retry) {
authLog("REDIRECT_TO_LOGIN", `재시도 후에도 401 (${url}) → 로그인 리다이렉트`);
@@ -523,13 +530,13 @@ export const apiCall = async <T>(
return response.data;
} catch (error: unknown) {
const axiosError = error as AxiosError;
const data = axiosError.response?.data as
| { message?: string; errorCode?: string; error?: { code?: string } }
| undefined;
return {
success: false,
message:
(axiosError.response?.data as { message?: string })?.message ||
axiosError.message ||
"알 수 없는 오류가 발생했습니다.",
errorCode: (axiosError.response?.data as { errorCode?: string })?.errorCode,
message: data?.message || axiosError.message || "알 수 없는 오류가 발생했습니다.",
errorCode: data?.errorCode || data?.error?.code,
};
}
};