import { useState } from "react"; import { useTranslation } from "react-i18next"; import { login, type SessionUser } from "./api.js"; export function Login({ onLoggedIn }: { onLoggedIn: (u: SessionUser) => void }) { const { t } = useTranslation(); const [username, setUsername] = useState(""); const [password, setPassword] = useState(""); const [error, setError] = useState(null); const [busy, setBusy] = useState(false); async function submit(e: React.FormEvent) { e.preventDefault(); setBusy(true); setError(null); try { onLoggedIn(await login(username, password)); } catch (err) { setError((err as Error).message); } finally { setBusy(false); } } return (

{t("auth.title")}

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

{error}

}
); }