카카오 로그인 및 비로그인 플로우 적용 .

This commit is contained in:
HyeongBaeYang committed 2026-01-21 16:09:29 +09:00
1 parent 2acf4e2cb6
commit 662b6b80bc
15 files changed
+1393 -335

No files matched your search

+72 -4
View File
@@ -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<LoginSectionProps> = ({ onBack, onLogin }) => {
const [isLoading, setIsLoading] = useState(false);
const [error, setError] = useState<string | null>(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 (
<div className="login-container">
{/* Back Button */}
<button onClick={onBack} className="login-back-btn">
<button onClick={onBack} className="login-back-btn" disabled={isLoading}>
<img src="/assets/images/icon-back.svg" alt="Back" />
<span>뒤로가기</span>
</button>
@@ -21,9 +78,20 @@ const LoginSection: React.FC<LoginSectionProps> = ({ onBack, onLogin }) => {
<img src="/assets/images/login-logo.svg" alt="CASTAD" />
</div>
{/* Error Message */}
{error && (
<div className="login-error">
{error}
</div>
)}
{/* Kakao Login Button */}
<button onClick={onLogin} className="btn-kakao">
카카오로 시작하기
<button
onClick={handleKakaoLogin}
className="btn-kakao"
disabled={isLoading}
>
{isLoading ? '로그인 중...' : '카카오로 시작하기'}
</button>
</div>
</div>