import { useDisclosure } from '@mantine/hooks';
import { IconAt } from '@tabler/icons-react';
import { Paper, Text, TextInput, PasswordInput, Button, rem} from "@mantine/core";
import {useState} from 'react';
import {http} from "../middleware/axiosConfig";
import { useNavigate } from 'react-router-dom';
import {useForm} from 'react-hook-form'
const Login = () => {
const navigate = useNavigate();
const {register, handleSubmit, } = useForm({
defaultValue: {
email: '',
password: ''
}
})
const {formState: { errors }} = useForm();
const [loginError, setloginError] = useState(false);
const onLogin = async (e) => {
try {
setloginError(false);
await http.get("/sanctum/csrf-cookie");
const res = await http.post("/api/login", e);
if (res.status === 200){
navigate("/lists");
}
}
catch (error) {
if (error.response.status === 401) {
setloginError(true);
}
}
};
const icon =