"use client"; import { FormEvent, useState } from "react"; import { useRouter } from "next/navigation"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; export function RegisterForm() { const router = useRouter(); const [email, setEmail] = useState(""); const [username, setUsername] = useState(""); const [displayName, setDisplayName] = useState(""); const [password, setPassword] = useState(""); const [error, setError] = useState(null); const [pending, setPending] = useState(false); async function onSubmit(event: FormEvent) { event.preventDefault(); setError(null); setPending(true); const response = await fetch("/api/register", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ email, username, displayName, password }) }); const payload = (await response.json().catch(() => null)) as { message?: string } | null; setPending(false); if (!response.ok) { setError(payload?.message ?? "Could not create account"); return; } router.push("/login?registered=1"); } return (

Password must be at least 8 chars and include uppercase, lowercase, and a number.

{error ?

{error}

: null}
); }