add form errors
This commit is contained in:
@@ -4,6 +4,7 @@ import axios from "axios";
|
||||
import {Link, useNavigate} from "react-router-dom";
|
||||
import useAuthUser from "../../hooks/AuthUser";
|
||||
import Card from "../../components/Card";
|
||||
import useAxiosTools from "../../hooks/AxiosTools";
|
||||
|
||||
const Login = () => {
|
||||
|
||||
@@ -11,16 +12,18 @@ const Login = () => {
|
||||
const {setAuthUser} = useAuthUser()
|
||||
const [email, setEmail] = useState('')
|
||||
const [password, setPassword] = useState('')
|
||||
const {errorCatch, errorLabel, cleanErrors, axiosGet, axiosPost} = useAxiosTools()
|
||||
|
||||
const handleSubmit = async (event: FormEvent) => {
|
||||
event.preventDefault()
|
||||
try {
|
||||
await axios.get('/sanctum/csrf-cookie')
|
||||
const res = await axios.post('/api/login', {email, password})
|
||||
cleanErrors()
|
||||
await axiosGet('/sanctum/csrf-cookie')
|
||||
const res = await axiosPost('/api/login', {email, password})
|
||||
setAuthUser(res.data.user)
|
||||
navigate('/')
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
errorCatch(e)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +33,7 @@ const Login = () => {
|
||||
<h1 className="text-center bg-blue-500 -mx-2 -mt-1 text-lg font-bold px-2 py-1 mb-2">
|
||||
Connexion
|
||||
</h1>
|
||||
{errorLabel()}
|
||||
|
||||
<Field type="email"
|
||||
name="email"
|
||||
|
||||
Reference in New Issue
Block a user