'use client'; import { useState, FormEvent } from 'react'; import { useRouter } from 'next/navigation'; export default function AuthPage() { const [password, setPassword] = useState(''); const [error, setError] = useState(''); const router = useRouter(); const handleSubmit = async (e: FormEvent) => { e.preventDefault(); try { const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/auth/verify`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ password }), }); if (response.ok) { const data = await response.json(); localStorage.setItem('authToken', data.token); router.push('/'); } else { setError('密码错误'); } } catch (err) { setError('验证失败,请重试'); } }; return (

请输入访问密码

setPassword(e.target.value)} className="w-full p-3 border rounded-md bg-light-primary dark:bg-dark-primary" placeholder="输入密码" required />
{error && (

{error}

)}
); }