import { useState } from 'react'; import { setToken, setSessionUser } from '../lib/session'; type Props = { onLogin: () => void }; export function LoginPage({ onLogin }: Props) { const [username, setUsername] = useState('admin'); const [password, setPassword] = useState('admin'); const [error, setError] = useState(''); const [loading, setLoading] = useState(false); const submit = async (e: React.FormEvent) => { e.preventDefault(); setLoading(true); setError(''); try { const body = new URLSearchParams(); body.set('username', username); body.set('password', password); const res = await fetch('/backend/auth/token', { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, body: body.toString(), }); if (!res.ok) { const data = await res.json().catch(() => null); throw new Error(data?.detail ?? 'Login fallito'); } const { access_token } = await res.json(); setToken(access_token); const meRes = await fetch('/backend/auth/me', { headers: { Authorization: `Bearer ${access_token}` }, }); if (meRes.ok) setSessionUser(await meRes.json()); onLogin(); } catch (err) { setError(err instanceof Error ? err.message : 'Login fallito'); } finally { setLoading(false); } }; return (

NetMapper auth

Accedi al book of truth

L'accesso รจ protetto per impedire lettura e modifica dei dati da terzi.

{error &&

{error}

}
); }