"use client"; import { useState } from "react"; import { browserFetch } from "../lib/api"; import { notifyAuthChanged } from "../lib/authEvents"; export default function RegisterForm({ redirectTo = "/account" }: { redirectTo?: string }) { const [error, setError] = useState(""); const [form, setForm] = useState({ fullName: "", email: "", password: "" }); async function onSubmit(event: React.FormEvent) { event.preventDefault(); setError(""); try { await browserFetch("/auth/register", { method: "POST", body: JSON.stringify(form) }); notifyAuthChanged("login"); window.location.href = redirectTo; } catch (submitError) { setError(submitError instanceof Error ? submitError.message : "No se pudo crear la cuenta"); } } return (
setForm((current) => ({ ...current, fullName: event.target.value }))} required /> setForm((current) => ({ ...current, email: event.target.value }))} required /> setForm((current) => ({ ...current, password: event.target.value }))} required /> {error ?

{error}

: null}
); }