diff --git a/client/src/pages/Login.tsx b/client/src/pages/Login.tsx index 8e5f516..96ac5c2 100644 --- a/client/src/pages/Login.tsx +++ b/client/src/pages/Login.tsx @@ -1,4 +1,4 @@ -import { useState } from "react"; +import { useState, useEffect } from "react"; import { Button } from "@/components/ui/button"; import { Card, CardContent } from "@/components/ui/card"; import { Input } from "@/components/ui/input"; @@ -10,9 +10,33 @@ import { toast } from "sonner"; const ITINOVA_LOGO = "https://d2xsxph8kpxj0f.cloudfront.net/310519663070627318/fo4DRyBgjsuiigFAgNLuWm/itinova-logo_2a2ba00a.jpg"; const SANTINOVA_LOGO = "https://d2xsxph8kpxj0f.cloudfront.net/310519663070627318/fo4DRyBgjsuiigFAgNLuWm/santinova-logo_5ae0d248.webp"; +// Logo Microsoft SVG officiel +function MicrosoftLogo() { + return ( + + ); +} + export default function Login() { const [username, setUsername] = useState(""); const [password, setPassword] = useState(""); + const [azureLoading, setAzureLoading] = useState(false); + + // Afficher les erreurs transmises via query param (ex: depuis le callback Azure) + useEffect(() => { + const params = new URLSearchParams(window.location.search); + const error = params.get("error"); + if (error) { + toast.error(decodeURIComponent(error)); + // Nettoyer l'URL + window.history.replaceState({}, "", "/login"); + } + }, []); const loginMutation = trpc.auth.loginLocal.useMutation({ onSuccess: () => { @@ -24,11 +48,36 @@ export default function Login() { }, }); + const azureLoginQuery = trpc.auth.getAzureLoginUrl.useQuery(undefined, { + enabled: false, + retry: false, + }); + + const azureAvailableQuery = trpc.auth.isAzureAdAvailable.useQuery(); + const handleLocalLogin = (e: React.FormEvent) => { e.preventDefault(); loginMutation.mutate({ email: username, password }); }; + const handleMicrosoftLogin = async () => { + setAzureLoading(true); + try { + const result = await azureLoginQuery.refetch(); + if (result.data?.url) { + window.location.href = result.data.url; + } else { + toast.error("Impossible d'obtenir l'URL de connexion Microsoft"); + setAzureLoading(false); + } + } catch { + toast.error("Erreur lors de la connexion Microsoft"); + setAzureLoading(false); + } + }; + + const azureAvailable = azureAvailableQuery.data?.available ?? false; + return (
Connectez-vous pour accéder à l'application