import { useState } from "react"; import { Button } from "react-bootstrap"; import { useNavigate } from "react-router-dom"; import { useCookies } from "react-cookie"; const Login = () => { const [cookies, setCookie] = useCookies(['name']); const [rememberme, setPersistence] = useState(true); const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [returnmess, returnMessage] = useState(""); const [isLoading, setLoading] = useState(false); const navigate = useNavigate(); const handleLogin = async (e) => { setLoading(true); e.preventDefault(); const response = await fetch(`https://localhost:7292/api/Login?rememberMe=${rememberme}`, { method: 'POST', credentials: 'include', headers: { 'Accept': 'text/json', 'Content-Type': 'text/json' }, body: JSON.stringify({ email, password }) }); if (response.status === 200) { var rep = await response.json(); if (rep.succeeded === true) { const confirm = await fetch(`https://localhost:7292/api/WhoAmI`, { method: 'GET', credentials: 'include', headers: { 'Accept': 'text/json', 'Content-Type': 'text/json' } }); const user = await confirm.json(); setCookie('GMGM', {...user, LoggedIn:true}, { path: '/', SameSite:'strict' }) navigate("/"); } else { returnMessage("L'adresse courriel ou le mot de passe est incorrect."); setCookie('GMGM', {LoggedIn:false}, { path: '/', SameSite:'strict' }) } } else { returnMessage("Erreur d'API, veuillez réessayer plus tard.") setCookie('GMGM', {LoggedIn:false}, { path: '/', SameSite:'strict' }) } setPassword(""); setLoading(false); } if (isLoading) return (
) return (

Connexion

{returnmess}
setEmail(e.target.value)} />
setPassword(e.target.value)} />
) } export default Login;