"use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; import Link from "next/link"; import { login, register, ApiError } from "@/lib/api"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; export default function LoginPage() { const router = useRouter(); const [username, setUsername] = useState(""); const [password, setPassword] = useState(""); const [error, setError] = useState(null); const [loading, setLoading] = useState(false); const [mode, setMode] = useState<"login" | "register">("login"); async function handleSubmit(event: React.FormEvent) { event.preventDefault(); setError(null); setLoading(true); try { if (mode === "login") { await login(username, password); } else { await register(username, password); } router.push("/"); } catch (err) { if (err instanceof ApiError) { setError(err.message); } else { setError("Something went wrong"); } } finally { setLoading(false); } } return (
{mode === "login" ? "Sign in" : "Create account"} {mode === "login" ? "Use the same credentials as your node agent and Finder." : "This account works across the web UI, node agent, and Finder."}
setUsername(e.target.value)} className="rounded-lg border border-input bg-background px-3 py-2 text-sm outline-none ring-ring focus:ring-2" placeholder="admin" />
setPassword(e.target.value)} className="rounded-lg border border-input bg-background px-3 py-2 text-sm outline-none ring-ring focus:ring-2" />
{error &&

{error}

}

{mode === "login" ? ( <> No account?{" "} ) : ( <> Already have an account?{" "} )}

); }