+
URL에서 가져온 정보로 영상이 자동 생성됩니다.
{error && (
diff --git a/src/pages/Login/LoginSection.tsx b/src/pages/Login/LoginSection.tsx
index 92ea686..ae259f2 100755
--- a/src/pages/Login/LoginSection.tsx
+++ b/src/pages/Login/LoginSection.tsx
@@ -1,5 +1,6 @@
-import React from 'react';
+import React, { useState, useEffect } from 'react';
+import { getKakaoLoginUrl, kakaoCallback } from '../../utils/api';
interface LoginSectionProps {
onBack: () => void;
@@ -7,10 +8,66 @@ interface LoginSectionProps {
}
const LoginSection: React.FC
= ({ onBack, onLogin }) => {
+ const [isLoading, setIsLoading] = useState(false);
+ const [error, setError] = useState(null);
+
+ // 카카오 콜백 처리 (URL에서 code 파라미터 확인)
+ useEffect(() => {
+ const urlParams = new URLSearchParams(window.location.search);
+ const code = urlParams.get('code');
+
+ if (code) {
+ handleKakaoCallback(code);
+ }
+ }, []);
+
+ const handleKakaoCallback = async (code: string) => {
+ setIsLoading(true);
+ setError(null);
+
+ try {
+ await kakaoCallback(code);
+
+ // URL에서 code 파라미터 제거
+ const url = new URL(window.location.href);
+ url.searchParams.delete('code');
+ window.history.replaceState({}, document.title, url.pathname);
+
+ // 로그인 성공
+ onLogin();
+ } catch (err) {
+ console.error('Kakao callback failed:', err);
+ setError('카카오 로그인에 실패했습니다. 다시 시도해주세요.');
+
+ // URL에서 code 파라미터 제거
+ const url = new URL(window.location.href);
+ url.searchParams.delete('code');
+ window.history.replaceState({}, document.title, url.pathname);
+ } finally {
+ setIsLoading(false);
+ }
+ };
+
+ const handleKakaoLogin = async () => {
+ setIsLoading(true);
+ setError(null);
+
+ try {
+ const response = await getKakaoLoginUrl();
+
+ // 카카오 로그인 페이지로 리다이렉트
+ window.location.href = response.auth_url;
+ } catch (err) {
+ console.error('Failed to get Kakao login URL:', err);
+ setError('로그인 URL을 가져오는데 실패했습니다. 다시 시도해주세요.');
+ setIsLoading(false);
+ }
+ };
+
return (
{/* Back Button */}
-
+ {/* Error Message */}
+ {error && (
+
+ {error}
+
+ )}
+
{/* Kakao Login Button */}
-
- 카카오로 시작하기
+
+ {isLoading ? '로그인 중...' : '카카오로 시작하기'}