069d544bb5
- non-admins now see ONLY their own sessions in /api/sessions (own app starts + own linked cards); gun scopes grant control, not visibility; admins see everything - Account page shows the logged-in user's permissions in plain words (Administrator badge, or the guns/relays they control), built solely from data already visible to them - Start button arms only when the gun reports Preparing (cable in the car); idle unplugged gun shows an explanatory hint instead - keep owner's app rename to 'Art IoT' - smoke test: 59 checks (gun-scoped user sees no foreign sessions)
65 lines
1.9 KiB
TypeScript
65 lines
1.9 KiB
TypeScript
import { FormEvent, useState } from "react";
|
|
import { api } from "../api";
|
|
import { useApp } from "../store";
|
|
import type { Me } from "../types";
|
|
|
|
export default function Login() {
|
|
const setMe = useApp((s) => s.setMe);
|
|
const [username, setUsername] = useState("");
|
|
const [password, setPassword] = useState("");
|
|
const [error, setError] = useState<string | null>(null);
|
|
const [busy, setBusy] = useState(false);
|
|
|
|
async function submit(e: FormEvent) {
|
|
e.preventDefault();
|
|
setBusy(true);
|
|
setError(null);
|
|
try {
|
|
const r = await api.post<{ user: Me }>("/login", { username, password });
|
|
setMe(r.user);
|
|
} catch (err) {
|
|
setError((err as Error).message);
|
|
} finally {
|
|
setBusy(false);
|
|
}
|
|
}
|
|
|
|
return (
|
|
<div className="login">
|
|
<form className="login__panel" onSubmit={submit}>
|
|
<div className="login__head">
|
|
<svg viewBox="0 0 100 100" className="login__mark" aria-hidden>
|
|
<path d="M55 12 L28 56 L46 56 L41 88 L72 42 L52 42 Z" />
|
|
</svg>
|
|
<h1>Art IoT</h1>
|
|
<p>Private charging backend — sign in to operate.</p>
|
|
</div>
|
|
<label className="field">
|
|
<span>Username</span>
|
|
<input
|
|
value={username}
|
|
onChange={(e) => setUsername(e.target.value)}
|
|
autoComplete="username"
|
|
autoFocus
|
|
required
|
|
/>
|
|
</label>
|
|
<label className="field">
|
|
<span>Password</span>
|
|
<input
|
|
type="password"
|
|
value={password}
|
|
onChange={(e) => setPassword(e.target.value)}
|
|
autoComplete="current-password"
|
|
required
|
|
/>
|
|
</label>
|
|
{error && <p className="field-error">{error}</p>}
|
|
<button className="btn btn--primary btn--block" disabled={busy}>
|
|
{busy ? "Signing in…" : "Sign in"}
|
|
</button>
|
|
</form>
|
|
</div>
|
|
);
|
|
}
|