import Link from "next/link"; import { useState } from "react"; import { useRouter } from "next/router"; interface FormData { name: string; email: string; password: string; } export default function Register() { const router = useRouter(); const [form, setForm] = useState({ name: "", email: "", password: "", }); async function registerUser() { let success: boolean = false; if (form.name != "" && form.email != "" && form.password != "") { await fetch("/api/auth/register", { body: JSON.stringify(form), headers: { "Content-Type": "application/json", }, method: "POST", }) .then((res) => { success = res.ok; return res.json(); }) .then((data) => console.log(data)); if (success) { setForm({ name: "", email: "", password: "", }); router.push("/login"); } } else { console.log("Please fill out all the fields."); } } return (

Linkwarden

setForm({ ...form, name: e.target.value })} className="border border-gray-700 rounded-md block m-2 mx-auto p-2" /> setForm({ ...form, email: e.target.value })} className="border border-gray-700 rounded-md block m-2 mx-auto p-2" /> setForm({ ...form, password: e.target.value })} className="border border-gray-700 rounded-md block m-2 mx-auto p-2" />
Register
Login
); }