refactor: Update authentication handling in authRoutes and useAuth hook
- Replaced the middleware `checkAuthStatus` with the `AuthController.checkAuthStatus` method in the authentication routes for improved clarity and structure. - Simplified token validation logic in the `useAuth` hook by removing unnecessary checks for expired tokens, allowing the API client to handle token refresh automatically. - Enhanced logging for authentication checks to provide clearer insights into the authentication flow and potential issues. - Adjusted the handling of user authentication status to ensure consistency and reliability in user state management. This refactor streamlines the authentication process and improves the overall maintainability of the authentication logic.
This commit is contained in:
@@ -329,6 +329,11 @@ apiClient.interceptors.request.use(
|
||||
const newToken = await refreshToken();
|
||||
if (newToken) {
|
||||
config.headers.Authorization = `Bearer ${newToken}`;
|
||||
} else {
|
||||
// 갱신 실패 시 인증 없는 요청을 보내면 TOKEN_MISSING 401 → 즉시 redirectToLogin 연쇄 장애
|
||||
// 요청 자체를 차단하여 호출부의 try/catch에서 처리하도록 함
|
||||
authLog("TOKEN_REFRESH_FAIL", `요청 인터셉터에서 갱신 실패 → 요청 차단 (${config.url})`);
|
||||
return Promise.reject(new Error("TOKEN_REFRESH_FAILED"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user