diff --git a/frontend/src/context/Auth/useAuth.js b/frontend/src/context/Auth/useAuth.js index b081bc0..68ac844 100644 --- a/frontend/src/context/Auth/useAuth.js +++ b/frontend/src/context/Auth/useAuth.js @@ -63,9 +63,8 @@ const useAuth = () => { setLoading(false); }, []); - const handleLogin = async (e, user) => { + const handleLogin = async user => { setLoading(true); - e.preventDefault(); try { const { data } = await api.post("/auth/login", user); @@ -78,11 +77,11 @@ const useAuth = () => { setIsAuth(true); toast.success(i18n.t("auth.toasts.success")); history.push("/tickets"); + setLoading(false); } catch (err) { toastError(err); + setLoading(false); } - - setLoading(false); }; const handleLogout = e => { diff --git a/frontend/src/pages/Login/index.js b/frontend/src/pages/Login/index.js index 4600680..ebb98d6 100644 --- a/frontend/src/pages/Login/index.js +++ b/frontend/src/pages/Login/index.js @@ -61,6 +61,11 @@ const Login = () => { setUser({ ...user, [e.target.name]: e.target.value }); }; + const handlSubmit = e => { + e.preventDefault(); + handleLogin(user); + }; + return ( @@ -71,11 +76,7 @@ const Login = () => { {i18n.t("login.title")} -
handleLogin(e, user)} - > + { const { isAuth, loading } = useContext(AuthContext); - if (loading) return ; - if (!isAuth && isPrivate) { return ( - + <> + {loading && } + + ); } if (isAuth && !isPrivate) { - return ; + return ( + <> + {loading && } + ; + + ); } - return ; + return ( + <> + {loading && } + + + ); }; export default RouteWrapper;