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 (