import { useState } from "react"; import { Button, Card, Center, PasswordInput, Stack, Text, TextInput, ThemeIcon, Title, } from "@mantine/core"; import { IconShieldLock, IconKey } from "@tabler/icons-react"; import { api, ApiError } from "./api"; import type { User } from "./types"; export function Login({ onLogin }: { onLogin: (u: User) => void }) { const [handle, setHandle] = useState(""); const [password, setPassword] = useState(""); const [busy, setBusy] = useState(false); const [error, setError] = useState(null); const ready = handle.trim().length > 0 && password.length > 0; const connect = async () => { if (!ready || busy) return; setBusy(true); setError(null); try { // La contraseña desbloquea la sesión del gateway (passphrase del operador). // El handle es solo el nombre a mostrar en esta iteración (wallet = fase 2). const me = await api.login(password); const h = handle.trim() || me.endpoint.slice(0, 8); onLogin({ id: me.endpoint, handle: h }); } catch (e) { setError(e instanceof ApiError ? e.message : "No se pudo conectar al gateway"); setBusy(false); } }; return (
unibus Mensajería cifrada de extremo a extremo setHandle(e.currentTarget.value)} onKeyDown={(e) => e.key === "Enter" && connect()} data-autofocus /> } value={password} onChange={(e) => setPassword(e.currentTarget.value)} onKeyDown={(e) => e.key === "Enter" && void connect()} /> {error && ( {error} )}
); }