"use client"; import Image from "next/image"; import { useSearchParams } from "next/navigation"; import { useState, Suspense } from "react"; function LoginForm() { const searchParams = useSearchParams(); const from = searchParams.get("from") || "/"; const [username, setUsername] = useState(""); const [password, setPassword] = useState(""); const [error, setError] = useState(""); const [loading, setLoading] = useState(false); async function handleSubmit(e: React.FormEvent) { e.preventDefault(); setError(""); setLoading(true); try { const res = await fetch("/api/auth/login", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ username, password }), }); if (res.ok) { window.location.href = from; } else { const data = await res.json().catch(() => ({})); setError(data.error || "Identifiants invalides"); } } catch { setError("Erreur réseau"); } finally { setLoading(false); } } return (
Administration