'use client'; import { useState } from 'react'; import { createBrowserClient } from '@supabase/ssr' import { useRouter } from 'next/navigation'; 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) { // Sign Up with Password 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); // Switch to login mode } } else { // Sign In with Password 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 (
사주 기록을 저장하고 언제든 다시 확인하세요
Supabase는 기본적으로 이메일 인증을 요구합니다. 가입 후 받은 메일의 링크를 클릭해야 로그인이 가능합니다.
(개발용 팁: Supabase 대시보드 > Authentication > Providers > Email > "Confirm email"를 끄면 인증 없이 바로 로그인 가능)