// app/app/auth/sign-up/page.tsx "use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; export default function SignUpPage() { const r = useRouter(); const [form, setForm] = useState({ username: "", email: "", password: "", agree: false }); const [busy, setBusy] = useState(false); const [err, setErr] = useState(null); const canSubmit = form.username.length >= 3 && form.password.length >= 8 && form.agree && !busy; async function submit() { setBusy(true); setErr(null); try { const res = await fetch("/api/auth/register", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ username: form.username.trim(), email: form.email.trim() || undefined, password: form.password, }), }); const j = await res.json(); if (!res.ok) throw new Error(j?.error || "Sign up failed"); // Auto-login right after register const login = await fetch("/api/auth/login", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ identifier: form.email.trim() || form.username.trim(), password: form.password }), }); const lj = await login.json(); if (!login.ok) throw new Error(lj?.error || "Auto login failed"); r.replace("/my-rigs"); // or wherever you want to land } catch (e: any) { setErr(e?.message || "Error"); } finally { setBusy(false); } } return (

Create Account

{err &&
{err}
}
Already have an account?{" "} Sign in
); }