"use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; import Link from "next/link"; export default function LoginPage() { const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [error, setError] = useState(""); const [loading, setLoading] = useState(false); const router = useRouter(); async function onSubmit(e) { e.preventDefault(); setError(""); setLoading(true); try { const r = await fetch("/api/login", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ email, password }), }); const data = await r.json(); if (!r.ok) { setError(data.error || "Error al iniciar sesión"); return; } router.push("/"); router.refresh(); } catch { setError("Error de conexión"); } finally { setLoading(false); } } return (
Bienvenido de nuevo a Nova Store.
¿No tenés cuenta? Registrate