'use client'; import { useState, useRef } from 'react'; import { useRouter } from 'next/navigation'; export default function LoginPage() { const router = useRouter(); const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [captcha, setCaptcha] = useState(''); const [error, setError] = useState(''); const [success, setSuccess] = useState(''); const captchaImgRef = useRef(null); const refreshCaptcha = () => { if (captchaImgRef.current) { captchaImgRef.current.src = `/api/captcha?${new Date().getTime()}`; } }; const handleLogin = async (e) => { e.preventDefault(); setError(''); setSuccess(''); const res = await fetch('/api/login', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ email, password, captcha }) }); const data = await res.json(); if (!res.ok) { setError(data.error); refreshCaptcha(); setCaptcha(''); } else { setSuccess(data.message); router.push(data.redirect || '/dash'); } }; return (