"use client"; import React, { useState, useTransition, Suspense } from "react"; import { useRouter, useSearchParams } from "next/navigation"; import { ShieldCheck, Lock, Mail, Eye, EyeOff, ArrowRight, Loader2, AlertCircle } from "lucide-react"; import toast from "react-hot-toast"; import { loginAdminAction } from "@/app/actions/auth"; function LoginForm() { const router = useRouter(); const searchParams = useSearchParams(); const from = searchParams.get("from") || "/dashboard"; const [identifier, setIdentifier] = useState(""); const [password, setPassword] = useState(""); const [showPassword, setShowPassword] = useState(false); const [rememberMe, setRememberMe] = useState(true); const [errorMessage, setErrorMessage] = useState(null); const [isPending, startTransition] = useTransition(); const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); setErrorMessage(null); if (!identifier.trim() || !password) { setErrorMessage("Veuillez remplir tous les champs."); return; } startTransition(async () => { try { const res = await loginAdminAction({ identifier: identifier.trim(), password, rememberMe, }); if (!res.success) { setErrorMessage(res.error || "Échec de l'authentification."); toast.error(res.error || "Erreur lors de la connexion"); return; } toast.success(`Bienvenue, ${res.user?.name || "Administrateur"} !`); // Full page redirect ensures middleware & server cookies are freshly synchronized window.location.href = from.startsWith("/") && !from.startsWith("//") && !from.startsWith("/\\") ? from : "/dashboard"; } catch (err) { console.error("Login client error:", err); setErrorMessage("Une erreur imprévue est survenue. Veuillez réessayer."); toast.error("Erreur serveur"); } }); }; return (
{/* Background ambient lighting */}
{/* Card Header & Brand */}

AfroAdmin

Portail d'administration sécurisé Afrohub

{/* Card Form */}
{errorMessage && (
{errorMessage}
)}
{/* Identifier (Email / Username) */}
setIdentifier(e.target.value)} disabled={isPending} className="w-full pl-11 pr-4 py-3 bg-slate-800/80 border border-slate-700/80 rounded-xl text-white placeholder-slate-500 text-sm focus:outline-none focus:border-indigo-500 focus:ring-2 focus:ring-indigo-500/20 transition-all disabled:opacity-50" />
{/* Password */}
setPassword(e.target.value)} disabled={isPending} className="w-full pl-11 pr-11 py-3 bg-slate-800/80 border border-slate-700/80 rounded-xl text-white placeholder-slate-500 text-sm focus:outline-none focus:border-indigo-500 focus:ring-2 focus:ring-indigo-500/20 transition-all disabled:opacity-50" />
{/* Remember Me */}
{/* Submit Button */}
{/* Security footnote */}
Chiffrement SHA-256 de session • Accès strictement restreint
{/* Brand copyright */}

© {new Date().getFullYear()} Afrohub. Tous droits réservés.

); } export default function LoginPage() { return (
} > ); }