From ca1c98b5936d470be3614cd22e6eb4bef0cd8400 Mon Sep 17 00:00:00 2001 From: heeyongKim <166043860+heeeeyong@users.noreply.github.com> Date: Sun, 17 Aug 2025 14:45:29 +0900 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=EC=BF=A0=ED=82=A4=20=EB=B0=A9?= =?UTF-8?q?=EC=8B=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/index.ts | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/api/index.ts b/src/api/index.ts index e0e2e4ff..043a2e00 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -17,26 +17,25 @@ export const apiClient = axios.create({ // const TEMP_ACCESS_TOKEN = // 'eyJhbGciOiJIUzI1NiJ9.eyJ1c2VySWQiOjEsImlhdCI6MTc1NDM4MjY1MiwiZXhwIjoxNzU2OTc0NjUyfQ.BSGuoMWlrzc0oKgSJXHEycxdzzY9-e7gD4xh-wSDemc'; -// Request 인터셉터: 쿠키가 없을 때 임시 토큰을 헤더에 추가 +// Request 인터셉터: temp_token과 access_token 쿠키 처리 apiClient.interceptors.request.use( config => { - // 쿠키에서 Authorization 확인 + // 쿠키에서 temp_token과 access_token 확인 const cookies = document.cookie.split(';'); - const hasAuthCookie = cookies.some(cookie => cookie.trim().startsWith('Authorization=')); - - // 쿠키가 없으면 임시 토큰을 헤더에 추가 (현재 주석처리됨) - // if (!hasAuthCookie) { - // console.log('🔑 쿠키가 없어서 임시 토큰을 헤더에 추가합니다.'); - // config.headers.Authorization = `Bearer ${TEMP_ACCESS_TOKEN}`; - // } else { - // console.log('✅ Authorization 쿠키가 있어서 자동으로 전송됩니다.'); - // } - - // 쿠키만 테스트하기 위해 로그만 출력 - if (hasAuthCookie) { - console.log('✅ Authorization 쿠키가 있어서 자동으로 전송됩니다.'); + const hasTempToken = cookies.some(cookie => cookie.trim().startsWith('temp_token=')); + const hasAccessToken = cookies.some(cookie => cookie.trim().startsWith('access_token=')); + + if (hasAccessToken) { + // access_token이 있으면 정상 토큰 사용 + console.log('✅ access_token 쿠키가 있어서 정상 토큰을 사용합니다.'); + // access_token은 withCredentials: true로 자동 전송되므로 별도 헤더 설정 불필요 + } else if (hasTempToken) { + // temp_token이 있으면 임시 토큰 사용 + console.log('🔑 temp_token 쿠키가 있어서 임시 토큰을 사용합니다.'); + // temp_token도 withCredentials: true로 자동 전송되므로 별도 헤더 설정 불필요 } else { - console.log('🔑 Authorization 쿠키가 없습니다.'); + // 둘 다 없으면 인증 토큰 없음 + console.log('❌ temp_token과 access_token 쿠키가 모두 없습니다.'); } return config; From e1148bdc6d1955a7f83ccae0f81e43b839a05ed3 Mon Sep 17 00:00:00 2001 From: heeyongKim <166043860+heeeeyong@users.noreply.github.com> Date: Sun, 17 Aug 2025 14:47:59 +0900 Subject: [PATCH 2/2] =?UTF-8?q?test:=20=EC=86=8C=EC=85=9C=EB=A1=9C?= =?UTF-8?q?=EA=B7=B8=EC=9D=B8=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/useOAuthToken.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hooks/useOAuthToken.ts b/src/hooks/useOAuthToken.ts index 9d6f63d5..a3a138bb 100644 --- a/src/hooks/useOAuthToken.ts +++ b/src/hooks/useOAuthToken.ts @@ -18,7 +18,7 @@ export const useOAuthToken = () => { // 서버에 토큰 발급 요청 apiClient - .post('/auth/set-cookie', { loginTokenKey }, { withCredentials: true }) + .post('/api/set-cookie', { loginTokenKey }, { withCredentials: true }) .then(response => { console.log('✅ 토큰 발급 성공:', response.data); // URL에서 code 파라미터 제거