// app/auth/sign-up/sign-up.tsx "use client"; import { useState, useCallback } from "react"; import { useRouter } from "next/navigation"; type Props = { nextPath?: string }; export default function SignUp({ nextPath = "/portal" }: Props) { const router = useRouter(); const [username, setUsername] = useState(""); const [email, setEmail] = useState(""); // optional if your backend allows const [password, setPassword] = useState(""); const [showPassword, setShowPassword] = useState(false); const [loading, setLoading] = useState(false); const [err, setErr] = useState(null); const onSubmit = useCallback(async (e: React.FormEvent) => { e.preventDefault(); setErr(null); setLoading(true); try { const res = await fetch("/api/auth/register", { method: "POST", credentials: "include", headers: { "Content-Type": "application/json", Accept: "application/json" }, body: JSON.stringify({ username, email: email || undefined, password }), }); const txt = await res.text(); let j: any = null; try { j = txt ? JSON.parse(txt) : null; } catch {} if (!res.ok) { const message = j?.error || j?.message || `Sign-up failed (${res.status})`; throw new Error(message); } router.replace(nextPath); // ALWAYS /portal router.refresh(); } catch (e: any) { setErr(e?.message || "Unable to sign up."); } finally { setLoading(false); } }, [username, email, password, nextPath, router]); return (

Create Account

Join MakerDash to manage rigs, settings, and projects.

setUsername(e.currentTarget.value)} required />
setEmail(e.currentTarget.value)} />
setPassword(e.currentTarget.value)} required minLength={8} />
{err && (
{err}
)}
Already have an account?{" "} Sign in
); }