import React, { useState } from 'react'; import { Link, Redirect } from 'react-router-dom'; import { Form, Col, Container, Button, Row, Alert } from 'react-bootstrap'; import axios from 'axios' import catchErrors from '../utils/catchErrors' import { handleLogin } from '../utils/auth' const INIT_USER = { id: '', password: '' } function Login() { const [validated, setValidated] = useState(false); const [user, setUser] = useState(INIT_USER) const [error, setError] = useState('') const [success, setSuccess] = useState(false) function handleChange(event) { const { name, value } = event.target setUser({ ...user, [name]: value }) } async function handleSubmit(event) { event.preventDefault() const form = event.currentTarget; if (form.checkValidity() === false) { event.preventDefault(); event.stopPropagation(); } setValidated(true); try { setError('') const response=await axios.post('/api/auth/login', user) handleLogin(response.data) setSuccess(true) } catch (error) { catchErrors(error, setError) } } if (success) { alert('로그인 되었습니다.') window.location.href='/' } return (

Login

{error && {error} }
아이디 아이디를 입력하세요. 비밀번호 비밀번호를 입력하세요.
회원이 아니십니까?
) } export default Login