diff --git a/src/components/Login.js b/src/components/Login.js index c132c8b..8f193d8 100644 --- a/src/components/Login.js +++ b/src/components/Login.js @@ -1,8 +1,8 @@ import React, { useState, useRef } from "react"; +import {useNavigate} from 'react-router-dom'; import Form from "react-validation/build/form"; import Input from "react-validation/build/input"; import CheckButton from "react-validation/build/button"; - import AuthService from "../services/auth.service"; const required = (value) => { @@ -18,6 +18,7 @@ const required = (value) => { const Login = (props) => { const form = useRef(); const checkBtn = useRef(); + const navigate = useNavigate(); const [username, setUsername] = useState(""); const [password, setPassword] = useState(""); @@ -41,11 +42,12 @@ const Login = (props) => { setLoading(true); form.current.validateAll(); + if (checkBtn.current.context._errors.length === 0) { AuthService.login(username, password).then( () => { - props.history.push("/profile"); + navigate("/profile"); window.location.reload(); }, (error) => {