"use client"; import { useState } from "react"; import { createClient } from "@/lib/supabase/client"; import { useRouter } from "next/navigation"; import Image from "next/image"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Alert, AlertDescription } from "@/components/ui/alert"; import { Loader2, Mail, Lock, Shield } from "lucide-react"; export default function LoginPage() { const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [loading, setLoading] = useState(false); const [error, setError] = useState(""); const router = useRouter(); // Fonction pour traduire les erreurs Supabase en français const getErrorMessage = (error: string) => { const errorMessages: { [key: string]: string } = { "Invalid login credentials": "Identifiants de connexion invalides", "Email not confirmed": "Email non confirmé", "Too many requests": "Trop de tentatives de connexion", "User not found": "Utilisateur non trouvé", "Invalid email": "Adresse email invalide", "Password should be at least 6 characters": "Le mot de passe doit contenir au moins 6 caractères", "Email rate limit exceeded": "Limite de tentatives dépassée", "Invalid email or password": "Email ou mot de passe incorrect", "Account not found": "Compte non trouvé", "Invalid credentials": "Identifiants incorrects", "Authentication failed": "Échec de l'authentification", "Access denied": "Accès refusé", "Unauthorized": "Non autorisé", }; // Chercher une correspondance exacte if (errorMessages[error]) { return errorMessages[error]; } // Chercher une correspondance partielle for (const [englishError, frenchError] of Object.entries(errorMessages)) { if (error.toLowerCase().includes(englishError.toLowerCase())) { return frenchError; } } // Message par défaut si aucune correspondance return "Erreur de connexion. Vérifiez vos identifiants."; }; const handleLogin = async (e: React.FormEvent) => { e.preventDefault(); setLoading(true); setError(""); // Validation côté client if (!email || !password) { setError("Veuillez remplir tous les champs"); setLoading(false); return; } if (!email.includes("@")) { setError("Veuillez entrer une adresse email valide"); setLoading(false); return; } const supabase = createClient(); try { const { data, error: authError } = await supabase.auth.signInWithPassword({ email, password, }); if (authError) { setError(getErrorMessage(authError.message)); return; } if (data.user) { router.push("/"); router.refresh(); } } catch (error) { console.error('Login error:', error); setError("Une erreur inattendue est survenue. Veuillez réessayer."); } finally { setLoading(false); } }; return (
Logo
Admin Dashboard

Connectez-vous pour accéder au tableau de bord

{error && ( {error} )}
setEmail(e.target.value)} className="pl-10 border-gray-300 focus:border-gray-900 focus:ring-gray-900" required />
setPassword(e.target.value)} className="pl-10 border-gray-300 focus:border-gray-900 focus:ring-gray-900" required />

Accès réservé aux administrateurs autorisés

); }