"use client"; import { useState } from "react"; import Link from "next/link"; import { useRouter } from "next/navigation"; import { createClient } from "@/lib/supabase/client"; import Button from "@/components/ui/Button"; import Input from "@/components/ui/Input"; export default function LoginPage() { const router = useRouter(); const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const handleLogin = async (e: React.FormEvent) => { e.preventDefault(); setLoading(true); setError(null); try { const supabase = createClient(); const { data: authData, error: authError } = await supabase.auth.signInWithPassword({ email, password, }); if (authError) { if (authError.message.includes("Invalid login credentials")) { setError("Email ou mot de passe incorrect."); } else { setError(authError.message); } return; } // Vérifier si l'utilisateur est admin pour la redirection if (authData.user) { const { data: profile } = await supabase .from("profiles") .select("is_admin") .eq("id", authData.user.id) .single(); if (profile && (profile as { is_admin?: boolean }).is_admin) { router.push("/admin"); router.refresh(); return; } } router.push("/dashboard"); router.refresh(); } catch { setError("Erreur de connexion. Veuillez réessayer."); } finally { setLoading(false); } }; return (
{/* Logo */}
H
HookLab

Content de te revoir

Connecte-toi pour accéder à tes formations.

{/* Form */}
setEmail(e.target.value)} required /> setPassword(e.target.value)} required /> {error && (

{error}

)}

Pas encore de compte ?{" "} Candidater

); }