'use client'; import { useRouter, useSearchParams } from 'next/navigation'; import { Suspense, useState } from 'react'; import { ThemeToggle } from '@/components/ThemeToggle'; function LoginPageClient() { const router = useRouter(); const searchParams = useSearchParams(); const [password, setPassword] = useState(''); const [error, setError] = useState(null); const [loading, setLoading] = useState(false); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(null); if (!password) return; try { setLoading(true); const res = await fetch('/api/login', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ password }), }); if (res.ok) { const redirect = searchParams.get('redirect') || '/'; router.replace(redirect); } else if (res.status === 401) { setError('密码错误'); } else { const data = await res.json().catch(() => ({})); setError(data.error ?? '服务器错误'); } } finally { setLoading(false); } }; return (

MoonTV

setPassword(e.target.value)} />
{error && (

{error}

)}
); } export default function LoginPage() { return ( ); }