Modulo makers3d desarrollado con codex V 0.0.1

This commit is contained in:
Ryuk Mike
2026-07-29 23:58:58 +02:00
commit 2bedf7cbb7
171 changed files with 29421 additions and 0 deletions
+35
View File
@@ -0,0 +1,35 @@
"use client";
import { useState } from "react";
import { browserFetch } from "../lib/api";
import { notifyAuthChanged } from "../lib/authEvents";
export default function LoginForm({ redirectTo = "/account" }: { redirectTo?: string }) {
const [error, setError] = useState("");
const [form, setForm] = useState({ email: "", password: "" });
async function onSubmit(event: React.FormEvent<HTMLFormElement>) {
event.preventDefault();
setError("");
try {
const response = await browserFetch<{ user: { role: string } }>("/auth/login", {
method: "POST",
body: JSON.stringify(form)
});
notifyAuthChanged("login");
window.location.href = response.user.role === "admin" ? "/app/backoffice" : redirectTo;
} catch (submitError) {
setError(submitError instanceof Error ? submitError.message : "No se pudo entrar");
}
}
return (
<form className="stack" onSubmit={onSubmit}>
<input className="field" type="email" placeholder="Correo" value={form.email} onChange={(event) => setForm((current) => ({ ...current, email: event.target.value }))} required />
<input className="field" type="password" placeholder="Contrasena" value={form.password} onChange={(event) => setForm((current) => ({ ...current, password: event.target.value }))} required />
<button className="button button-primary" type="submit">Entrar</button>
{error ? <p className="muted">{error}</p> : null}
</form>
);
}