import { useState } from 'react'; import { login, ApiError } from '../../../lib/api'; import { useAuth } from '../../../stores/auth'; export default function Login() { const [value, setValue] = useState(''); const [error, setError] = useState(null); const [busy, setBusy] = useState(false); const setLoggedIn = useAuth(s => s.setLoggedIn); async function handleSubmit(e: React.SyntheticEvent) { e.preventDefault(); const token = value.trim(); if (!token) return; setBusy(true); setError(null); try { await login(token); setLoggedIn(true); window.location.href = '/admin'; } catch (e) { if (e instanceof ApiError && e.status === 401) { setError('That key does not open this door.'); } else { setError('Could not reach the door. Try again.'); } setBusy(false); } } return (
Artist's entrance

Sign in

Present your token to enter the back room.

setValue(e.target.value)} autoComplete="current-password" aria-invalid={error ? true : undefined} aria-describedby={error ? 'login-error' : undefined} className="field-input font-mono tracking-widest" placeholder="••••••••••••" />
{error && ( )}
Back to the catalogue
); }