import { Link, useNavigate } from "react-router-dom"; import React, { useState, useEffect, FormEvent } from "react"; import { LoginUser } from "../types"; import { catchErrors } from "../helpers"; import { useAuth } from "./auth.context"; export default function Login() { const [user, setUser] = useState({ email: "", password: "", }); const [loading, setLoading] = useState(false); const [error, setError] = useState(""); const [disabled, setDisabled] = useState(false); const [success, setSuccess] = useState(false); const navigate = useNavigate(); const { login } = useAuth(); useEffect(() => { setDisabled(!(user.email && user.password)); }, [user]); function handleChange(event: React.ChangeEvent) { const { name, value } = event.currentTarget; setUser({ ...user, [name]: value }); } async function handleSubmit(event: FormEvent) { event.preventDefault(); try { setError(""); console.log("user data", user); // setLoading(true); await login(user.email, user.password, () => { navigate("/", { replace: true }); }); // console.log("서버연결됬나요", res); // console.log("로그인"); // setSuccess(true); // setError(""); } catch (error) { console.log("에러발생"); // setError("이메일 혹은 비밀번호를 다시 입력해주세요."); catchErrors(error, setError); } finally { setLoading(false); } } return (
Travel Report
); }