import React, { useState, useEffect } from 'react'; import axios from 'axios' import { Button, Form, Container, Navbar, Spinner, Alert } from 'react-bootstrap'; import catchErrors from '../utils/catchErrors' import { Link, Redirect } from 'react-router-dom' import { handleLogin } from '../utils/auth' import Menu from '../Components/Menu'; const INIT_USER = { email: '', password: '', } function LogIn() { const [user, setUser] = useState(INIT_USER) const [disabled, setDisabled] = useState(true) const [error, setError] = useState('') const [success, setSucces] = useState(false) const [loading, setLoading] = useState(false) useEffect(() => { const isUser = Object.values(user).every(el => Boolean(el)) isUser ? setDisabled(false) : setDisabled(true) }, [user]) function handleChange(event) { const { name, value } = event.target setUser({ ...user, [name]: value }) } async function handleSubmit(event) { event.preventDefault() try { setLoading(true) setError('') let res = await axios.post('/auth/login', user) handleLogin(res.data) setSucces(true) } catch (error) { catchErrors(error, setError) //setError(error.response.data) //error객체가 들어감. } finally { setLoading(false) } //server쪽에서 json형식으로 보낼것임 } //success시 링크이동 if (success) { console.log('success', success) alert('로그인 되었습니다!') return } return ( <> YDK Messenger

로그인

이메일 필수 정보입니다! 이메일을 입력해주세요! 비밀번호 필수 정보입니다! 비밀번호를 입력해주세요!
회원가입
{error && {error} }
); } export default LogIn