import { useState, type FormEvent } from "react"; import { Navigate, useLocation } from "react-router-dom"; import { useAuth } from "../auth/AuthContext"; import { toast } from "../components/Toaster"; import { btnPrimary, card, input } from "../components/ui"; export default function Login() { const { login, user } = useAuth(); const loc = useLocation() as { state?: { from?: string } }; const [u, setU] = useState(""); const [p, setP] = useState(""); const [busy, setBusy] = useState(false); if (user) return ; async function submit(e: FormEvent) { e.preventDefault(); setBusy(true); try { await login(u, p); } catch (err) { toast("err", err instanceof Error ? err.message : "登录失败"); } finally { setBusy(false); } } return (

BookLib 登录

setU(e.target.value)} aria-label="用户名" placeholder="用户名" autoFocus autoComplete="username" /> setP(e.target.value)} aria-label="密码" placeholder="密码" autoComplete="current-password" />
); }