import React, { useState, useEffect } from 'react'; import { AiOutlineSend } from 'react-icons/ai'; import { useNavigate } from 'react-router-dom'; import { useAuth } from '../Contexts/AuthContext'; import AuthService from '../services/AuthService'; import '../Style/Global.css'; const SignIn = () => { const navigate = useNavigate(); const { login } = useAuth(); const [error, setError] = useState(null); const [showConfirmation, setShowConfirmation] = useState(false); const handleSubmit = async (event: React.FormEvent) => { event.preventDefault(); try { const data = { pseudo: (event.target as any).pseudo.value, password: (event.target as any).password.value }; const validation = await AuthService.validateSignIn(data); if (!validation.valid) { setError(validation.error); } else { setError(null); const result = await AuthService.signIn(data); console.log(result); setShowConfirmation(true); setTimeout(async () => { await login(); navigate('/'); }, 1250); } } catch (error: any) { setError(error.message); } }; useEffect(() => { return () => { setShowConfirmation(false); }; }, []); return (

Log In

Mot de passe oublié ?

{error && (
{error}
)} {showConfirmation && (
Connexion réussie ! Vous serez redirigé vers votre profil.
)}
); }; export default SignIn;