@@ -9,10 +9,7 @@ export const useKakaoLogin = () => {
99
1010 const mutation = useMutation ( {
1111 mutationFn : async ( code : string ) => {
12- console . log ( '🔑 카카오 로그인 API 호출' ) ;
13-
1412 const redirect_uri = `${ window . location . origin } /oauth/kakao/redirect` ;
15- console . log ( '🔁 전달할 redirect_uri:' , redirect_uri ) ;
1613
1714 const response = await axios . post (
1815 `${ import . meta. env . VITE_API_URL } /oauth/login/kakao` ,
@@ -26,32 +23,26 @@ export const useKakaoLogin = () => {
2623 return response . data ;
2724 } ,
2825 onSuccess : ( data ) => {
29- console . log ( '✅ 로그인 성공' , data ) ;
30-
3126 const { access_token, refresh_token } = data . data ;
3227
3328 if ( access_token && refresh_token ) {
3429 setTokens ( access_token , refresh_token ) ;
3530 setAuthenticated ( true ) ;
36-
37- console . log ( '🔄 토큰 저장 완료' ) ;
38- console . log ( '📋 사용자 정보는 HomeProtectedRoute에서 자동으로 조회됩니다' ) ;
31+ } else {
32+ console . error ( '토큰이 응답에 없습니다:' , data ) ;
3933 }
4034 setLoading ( false ) ;
4135 } ,
4236 onError : ( error : unknown ) => {
43- // Axios 에러 타입 체크
4437 let errorMessage = "로그인에 실패했습니다." ;
4538
4639 if ( error && typeof error === 'object' && 'response' in error ) {
47- const axiosError = error as { response : { data : { message ?: string } } } ;
40+ const axiosError = error as { response : { data : { message ?: string } ; status ?: number } } ;
4841 if ( axiosError . response ?. data ?. message ) {
4942 errorMessage = axiosError . response . data . message ;
5043 }
5144 }
5245
53- console . error ( '❌ 로그인 실패:' , errorMessage ) ;
54-
5546 setAuthError ( errorMessage ) ;
5647 setLoading ( false ) ;
5748 } ,
@@ -60,29 +51,20 @@ export const useKakaoLogin = () => {
6051 const initiateKakaoLogin = ( ) => {
6152 setAuthError ( null ) ;
6253
63- // 환경 변수와 현재 도메인 정보 로깅
6454 const currentOrigin = window . location . origin ;
6555 const envRedirectUri = import . meta. env . VITE_KAKAO_REDIRECT_URI ;
6656 const isLocalhost = currentOrigin . includes ( 'localhost' ) ;
6757
68- // 환경별 리다이렉트 URI 결정
6958 let redirectUri : string ;
7059 if ( isLocalhost ) {
7160 redirectUri = envRedirectUri || 'http://localhost:3000/oauth/kakao/redirect' ;
7261 } else {
7362 redirectUri = envRedirectUri || `${ currentOrigin } /oauth/kakao/redirect` ;
7463 }
7564
76- console . log ( '🌍 현재 도메인:' , currentOrigin ) ;
77- console . log ( '⚙️ 환경변수 REDIRECT_URI:' , envRedirectUri ) ;
78- console . log ( '✅ 최종 사용할 REDIRECT_URI:' , redirectUri ) ;
79-
80- // prompt=login 추가로 강제 재로그인, nonce 추가로 캐시 방지
8165 const nonce = Date . now ( ) ;
8266 const kakaoAuthUrl = `https://kauth.kakao.com/oauth/authorize?client_id=${ import . meta. env . VITE_KAKAO_CLIENT_ID } &redirect_uri=${ encodeURIComponent ( redirectUri ) } &response_type=code&prompt=login&nonce=${ nonce } ` ;
8367
84- console . log ( '🔗 카카오 로그인 URL:' , kakaoAuthUrl ) ;
85-
8668 window . location . href = kakaoAuthUrl ;
8769 } ;
8870
0 commit comments