import { useState } from 'react' import { useNavigate, Link } from 'react-router-dom' export function LoginPage() { const navigate = useNavigate() const [username, setUsername] = useState('') const [password, setPassword] = useState('') const [error, setError] = useState(null) const [loading, setLoading] = useState(false) const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() setError(null) setLoading(true) try { const res = await fetch('/api/auth/login', { method: 'POST', headers: { 'Content-Type': 'application/json' }, credentials: 'include', body: JSON.stringify({ username, password }), }) if (!res.ok) { if (res.status === 401) { setError('Invalid username or password') } else { setError('Login failed. Please try again.') } return } // Redirect to dashboard on success navigate('/') } catch { setError('Network error. Is the server running?') } finally { setLoading(false) } } return (
zhealth

zhealth

Sign in to continue

setUsername(e.target.value)} autoComplete="username" required autoFocus />
setPassword(e.target.value)} autoComplete="current-password" required />
{error && (
{error}
)}

Don't have an account? Sign up

) }