// LoginScreen — sign in / create account. Reuses the onboard CSS palette so // new users land on something that feels like the rest of the app. On success, // api.login/register stores the returned token in localStorage and we reload // to re-bootstrap through getUser(). const { useState: useState_L } = React; function LoginScreen() { const [mode, setMode] = useState_L("signin"); // signin | register const [username, setU] = useState_L(""); const [password, setP] = useState_L(""); const [name, setName] = useState_L(""); const [busy, setBusy] = useState_L(false); const [err, setErr] = useState_L(""); const canSubmit = username.trim().length >= 3 && password.length >= 8 && (mode === "signin" || name.trim().length > 0); const submit = async (e) => { e?.preventDefault?.(); if (!canSubmit || busy) return; setBusy(true); setErr(""); try { if (mode === "signin") { await api.login({ username: username.trim(), password }); } else { await api.register({ username: username.trim(), password, name: name.trim() }); } // Fresh bootstrap — App reads /api/user, sees onboarded flag, routes correctly. location.reload(); } catch (ex) { const msg = ex?.status === 401 ? "Wrong username or password." : ex?.status === 409 ? "Username is taken." : ex?.status === 429 ? "Too many attempts. Wait a minute." : "Couldn't reach the server."; setErr(msg); } finally { setBusy(false); } }; return (