"use client"; import { useRouter } from "next/navigation"; import { useState } from "react"; export default function RegisterPage() { const router = useRouter(); const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [name, setName] = useState(""); const [error, setError] = useState(null); async function onSubmit(e: React.FormEvent) { e.preventDefault(); setError(null); const res = await fetch("/api/auth/register", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ email, password, name }), }); if (!res.ok) { const body = (await res.json().catch(() => ({}))) as { error?: string }; setError(body.error ?? "가입 실패"); return; } router.push("/login"); } return (

회원가입

setEmail(e.target.value)} className="rounded border px-3 py-2" /> setName(e.target.value)} className="rounded border px-3 py-2" /> setPassword(e.target.value)} className="rounded border px-3 py-2" /> {error != null &&

{error}

}
); }