"use client"; import { useRouter, useSearchParams } from "next/navigation"; import { Suspense, useEffect, useState } from "react"; import { api, ApiError } from "@/lib/api"; function LoginForm() { const router = useRouter(); const params = useSearchParams(); const [needsSetup, setNeedsSetup] = useState(false); const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [confirm, setConfirm] = useState(""); const [error, setError] = useState(null); const [busy, setBusy] = useState(false); useEffect(() => { api.get<{ needs_setup: boolean; authenticated: boolean }>("/api/auth/status").then((s) => { setNeedsSetup(s.needs_setup); if (s.authenticated) router.replace(params.get("next") || "/"); }).catch(() => {}); }, [router, params]); const submit = async (e: React.FormEvent) => { e.preventDefault(); setError(null); if (needsSetup && password !== confirm) return setError("Passwords do not match."); setBusy(true); try { await api.post(needsSetup ? "/api/auth/setup" : "/api/auth/login", { email, password }); router.replace(params.get("next") || "/"); } catch (err) { setError(err instanceof ApiError ? err.message : "Login failed"); } finally { setBusy(false); } }; return (
λ
LLM API
{needsSetup ? "Create the administrator account" : "Sign in to the console"}
{needsSetup && ( )} {error &&
{error}
}
Private system · all access is logged
); } export default function LoginPage() { return ; }