diff --git a/client/src/pages/LoginChoice.tsx b/client/src/pages/LoginChoice.tsx index d4948c4..0221c92 100644 --- a/client/src/pages/LoginChoice.tsx +++ b/client/src/pages/LoginChoice.tsx @@ -1,11 +1,21 @@ import { useLocation } from "wouter"; +import { useAuth } from "@/_core/hooks/useAuth"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; import { APP_LOGO, APP_TITLE, getLoginUrl } from "@/const"; import { KeyRound, Shield } from "lucide-react"; +import { useEffect } from "react"; export default function LoginChoice() { const [, setLocation] = useLocation(); + const { user, loading, isAuthenticated } = useAuth(); + + // Rediriger les utilisateurs déjà connectés vers le tableau de bord + useEffect(() => { + if (!loading && isAuthenticated && user?.role === 'admin') { + setLocation('/admin'); + } + }, [loading, isAuthenticated, user?.role, setLocation]); const handleManusLogin = () => { window.location.href = getLoginUrl(); @@ -15,6 +25,20 @@ export default function LoginChoice() { setLocation("/login"); }; + // Afficher un loader pendant la vérification de l'authentification + if (loading) { + return ( +