"use client"; import { useState } from "react"; import { signIn } from "next-auth/react"; import { useRouter } from "next/navigation"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { Lock } from "lucide-react"; import { toast } from "sonner"; export default function LoginPage() { const [password, setPassword] = useState(""); const [loading, setLoading] = useState(false); const router = useRouter(); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setLoading(true); try { const result = await signIn("credentials", { password, redirect: false, }); if (result?.error) { toast.error("Mot de passe incorrect"); setPassword(""); } else { toast.success("Connexion réussie"); router.push("/"); router.refresh(); } } catch { toast.error("Erreur lors de la connexion"); } finally { setLoading(false); } }; return (
Accès protégé Entrez le mot de passe pour accéder à l'application
setPassword(e.target.value)} placeholder="Entrez le mot de passe" disabled={loading} autoFocus onKeyDown={(e) => { if (e.key === "Enter") { handleSubmit(e); } }} />
); }