@@ -2,7 +2,8 @@ import { useEffect, useState } from 'react';
22import { useNavigate , useSearchParams } from 'react-router-dom' ;
33
44import { userApi } from '@/shared/apis/user' ;
5- import { useAuth } from '@/shared/context/AuthContext' ;
5+ import { LOGIN_METHOD_STORAGE_KEY , LOGIN_PROVIDER_HINT_KEY } from '@/shared/constants/authConstants' ;
6+ import { type LoginMethod , useAuth } from '@/shared/context/AuthContext' ;
67import { tokenUtils } from '@/shared/utils/auth' ;
78
89const AuthSuccessPage = ( ) => {
@@ -12,10 +13,35 @@ const AuthSuccessPage = () => {
1213 const [ errorMessage , setErrorMessage ] = useState < string > ( '' ) ;
1314
1415 useEffect ( ( ) => {
16+ const toLoginMethod = ( value : string | null | undefined ) : LoginMethod | null => {
17+ if ( value === 'email' || value === 'kakao' || value === 'google' || value === 'unknown' ) {
18+ return value ;
19+ }
20+ return null ;
21+ } ;
22+
23+ const determineLoginMethod = ( ) : LoginMethod => {
24+ const providerFromParam = toLoginMethod ( searchParams . get ( 'provider' ) ) ;
25+
26+ const providerHintRaw = sessionStorage . getItem ( LOGIN_PROVIDER_HINT_KEY ) ;
27+ const providerFromHint = toLoginMethod ( providerHintRaw ) ;
28+ if ( providerHintRaw ) {
29+ sessionStorage . removeItem ( LOGIN_PROVIDER_HINT_KEY ) ;
30+ }
31+
32+ const storedMethod = toLoginMethod ( localStorage . getItem ( LOGIN_METHOD_STORAGE_KEY ) ) ;
33+
34+ const resolvedMethod = providerFromParam ?? providerFromHint ?? storedMethod ?? 'unknown' ;
35+ console . log ( '🧭 [AUTH SUCCESS] 로그인 방식 판별:' , resolvedMethod ) ;
36+ return resolvedMethod ;
37+ } ;
38+
1539 const handleAuthSuccess = async ( ) => {
1640 console . log ( '🔄 [AUTH SUCCESS] OAuth 콜백 처리 시작' ) ;
1741 console . log ( '📝 [AUTH SUCCESS] URL 파라미터:' , Object . fromEntries ( searchParams ) ) ;
1842
43+ const loginMethod = determineLoginMethod ( ) ;
44+
1945 // URL 파라미터에서 에러 확인
2046 const error = searchParams . get ( 'error' ) ;
2147 if ( error ) {
@@ -71,14 +97,12 @@ const AuthSuccessPage = () => {
7197
7298 // 토큰이 있으면 login 함수 호출, 없으면 사용자 정보만으로도 처리
7399 if ( accessToken || currentToken ) {
74- login ( accessToken || currentToken || '' , userData ) ;
100+ login ( accessToken || currentToken || '' , userData , loginMethod ) ;
75101 console . log ( '✅ [AUTH SUCCESS] 로그인 완료 (토큰 저장)' ) ;
76102 } else {
77103 // HttpOnly 쿠키 방식인 경우, 토큰 없이 사용자 정보만 저장
78- // 이 경우 AuthContext를 수정해야 할 수도 있음
79104 console . log ( '✅ [AUTH SUCCESS] 로그인 완료 (HttpOnly 쿠키 방식)' ) ;
80- // 임시로 빈 토큰으로 처리 (나중에 AuthContext 수정 필요)
81- login ( 'http-only-cookie' , userData ) ;
105+ login ( 'http-only-cookie' , userData , loginMethod ) ;
82106 }
83107
84108 console . log ( '🏠 [AUTH SUCCESS] 홈으로 이동' ) ;
@@ -97,7 +121,7 @@ const AuthSuccessPage = () => {
97121 nickname : userInfo . nickname ,
98122 email : userInfo . email ,
99123 } ;
100- login ( existingToken , userData ) ;
124+ login ( existingToken , userData , loginMethod ) ;
101125 void navigate ( '/' , { replace : true } ) ;
102126 return ;
103127 } catch ( retryError ) {
0 commit comments