function LoginPage() { const { AppBootstrap } = window.__CRM__; const [email, setEmail] = React.useState(""); const [password, setPassword] = React.useState(""); const [csrf, setCsrf] = React.useState(""); const [err, setErr] = React.useState(""); React.useEffect(() => { (async () => { try { const r = await fetch("/auth/login.php", { credentials: "include", cache: "no-store" }); const j = await r.json(); setCsrf(j.csrf || ""); } catch { setErr("Falha ao iniciar sessão segura."); } })(); }, []); const valid = email.includes("@") && password.length >= 6; return ( Acesso {err && {err}}
{ if(!valid || !csrf){ e.preventDefault(); setErr("Preencha os campos. CSRF ausente."); } }}> setEmail(e.target.value)} margin="normal" required /> setPassword(e.target.value)} margin="normal" required inputProps={{ minLength: 6 }} /> Entrar
); } window.LoginPage = LoginPage;