"use client"; import { useState } from "react"; import Link from "next/link"; import { useRouter } from "next/navigation"; import { apiPost } from "@/lib/api"; export function AuthForm({ mode }: { mode: "login" | "register" }) { const router = useRouter(); const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [error, setError] = useState(""); const [busy, setBusy] = useState(false); const submit = async (event: React.FormEvent) => { event.preventDefault(); setBusy(true); setError(""); try { const path = mode === "login" ? "/api/auth/login" : "/api/auth/register"; await apiPost(path, { email, password }); if (mode === "register") { await apiPost("/api/auth/login", { email, password }); } router.push("/dashboard"); router.refresh(); } catch (err) { setError(err instanceof Error ? err.message : "Request failed"); } finally { setBusy(false); } }; return (

Animatrix

{mode === "login" ? "Sign in" : "Create account"}

{mode === "login" ? "Use your workspace account to open the generator." : "Create a local account for this workspace."}

setEmail(e.target.value)} /> setPassword(e.target.value)} /> {error ? (
{error}
) : null}
{mode === "login" ? ( <> No account yet? Register ) : ( <> Already registered? Sign in )}
); }