'use client'; import { useState } from 'react'; import { createBrowserClient } from '@supabase/ssr' import { useRouter } from 'next/navigation'; import Link from 'next/link'; export default function LoginPage() { const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [isSignUp, setIsSignUp] = useState(false); const [loading, setLoading] = useState(false); const router = useRouter(); const supabase = createBrowserClient( process.env.NEXT_PUBLIC_SUPABASE_URL!, process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY! ); const handleAuth = async (e: React.FormEvent) => { e.preventDefault(); setLoading(true); if (isSignUp) { const { data, error } = await supabase.auth.signUp({ email, password, options: { emailRedirectTo: `${window.location.origin}/auth/callback`, } }); if (error) { alert('회원가입 실패: ' + error.message); } else if (data.user && data.user.identities && data.user.identities.length === 0) { alert('이미 가입된 이메일입니다. 로그인해주세요.'); } else { alert('가입이 완료되었습니다! 이메일 인증 후 로그인해주세요.'); setIsSignUp(false); } } else { const { error } = await supabase.auth.signInWithPassword({ email, password, }); if (error) { alert('로그인 실패: ' + error.message); } else { router.push('/mypage'); router.refresh(); } } setLoading(false); }; const handleSocialLogin = async (provider: 'google' | 'kakao') => { const { error } = await supabase.auth.signInWithOAuth({ provider, options: { redirectTo: `${window.location.origin}/auth/callback`, }, }); if (error) alert('소셜 로그인 오류: ' + error.message); }; return (
사주 기록을 저장하고 언제든 다시 확인하세요