diff --git a/GrossesMitaines/GrossesMitainesAPI/Controllers/LoginController.cs b/GrossesMitaines/GrossesMitainesAPI/Controllers/LoginController.cs index a02de43..712e73c 100644 --- a/GrossesMitaines/GrossesMitainesAPI/Controllers/LoginController.cs +++ b/GrossesMitaines/GrossesMitainesAPI/Controllers/LoginController.cs @@ -46,6 +46,8 @@ public class LoginController : Controller { public SignInResult Login(LoginModel user, bool rememberMe = false) { var User = _userMan.FindByEmailAsync(user.email.ToUpper()); User.Wait(); + if (User.Result is null) + return new SignInResult(); var res = _signInMan.PasswordSignInAsync(User.Result, user.password, rememberMe, false); res.Wait(); return res.Result; diff --git a/GrossesMitaines/grosses-mitaines-ui/src/components/App.js b/GrossesMitaines/grosses-mitaines-ui/src/components/App.js index 62cb7bf..f832403 100644 --- a/GrossesMitaines/grosses-mitaines-ui/src/components/App.js +++ b/GrossesMitaines/grosses-mitaines-ui/src/components/App.js @@ -23,9 +23,9 @@ const App = () => { const response = await fetch(`https://localhost:7292/api/WhoAmI`, { credentials: 'include' }); if (response.status === 200) { var user = await response.json(); - setCookie('GMGM', {...user, LoggedIn:true}, { path: '/', sameSite:'strict' }) + setCookie('GMGM', {...user, LoggedIn:true}, { path: '/', SameSite:'strict' }) } - else setCookie('GMGM', {LoggedIn:false}, { path: '/', sameSite:'strict' }) + else setCookie('GMGM', {LoggedIn:false}, { path: '/', SameSite:'strict' }) } if (cookies.GMGM === null) { FetchUser(); diff --git a/GrossesMitaines/grosses-mitaines-ui/src/components/Topbar.js b/GrossesMitaines/grosses-mitaines-ui/src/components/Topbar.js index 92a4486..1685b62 100644 --- a/GrossesMitaines/grosses-mitaines-ui/src/components/Topbar.js +++ b/GrossesMitaines/grosses-mitaines-ui/src/components/Topbar.js @@ -14,14 +14,14 @@ const Topbar = () => { setLogin(cookies.GMGM ?? null); }); - function logOut() { + async function logOut() { const response = fetch(`https://localhost:7292/api/Logout`, { method: 'POST', credentials: 'include' }) - removeCookie("GMGM"); - setLogin(null); // Y U NO WORK?!? + await removeCookie("GMGM"); + await setLogin(null); // Y U NO WORK?!? } return ( diff --git a/GrossesMitaines/grosses-mitaines-ui/src/pages/Login.js b/GrossesMitaines/grosses-mitaines-ui/src/pages/Login.js index 1451f9b..e229e15 100644 --- a/GrossesMitaines/grosses-mitaines-ui/src/pages/Login.js +++ b/GrossesMitaines/grosses-mitaines-ui/src/pages/Login.js @@ -9,10 +9,12 @@ const Login = () => { 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}`, { @@ -37,21 +39,24 @@ const Login = () => { } }); const user = await confirm.json(); - setCookie('GMGM', {...user, LoggedIn:true}, { path: '/', sameSite:'strict' }) + 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' }) + setCookie('GMGM', {LoggedIn:false}, { path: '/', SameSite:'strict' }) } } else { returnMessage("Erreur d'API, veuillez réessayer plus tard.") - setCookie('GMGM', {LoggedIn:false}, { path: '/', sameSite:'strict' }) + setCookie('GMGM', {LoggedIn:false}, { path: '/', SameSite:'strict' }) } setPassword(""); + setLoading(false); } + if (isLoading) return (
) + return (