import { useState } from 'react'; import { X } from 'lucide-react'; import { useAuth } from '../contexts/AuthContext'; interface AuthModalProps { onClose: () => void; } export default function AuthModal({ onClose }: AuthModalProps) { const { signIn, signUp } = useAuth(); const [isSignUp, setIsSignUp] = useState(false); const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [loading, setLoading] = useState(false); const [error, setError] = useState(''); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(''); setLoading(true); try { const { error } = isSignUp ? await signUp(email, password) : await signIn(email, password); if (error) { setError(error.message); } else { onClose(); } } catch (err) { setError('发生错误,请重试'); } finally { setLoading(false); } }; return (

{isSignUp ? '注册账号' : '登录账号'}

setEmail(e.target.value)} className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent" placeholder="your@email.com" required />
setPassword(e.target.value)} className="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent" placeholder="••••••••" required minLength={6} />
{error && (
错误: {error}
)}
); }