Login.js 1.17 KB
import React,{useState} from 'react';
import LoginForm from '../component/LoginForm';
import { getLoginInfo } from '../lib/api/login';
import {Redirect, withRouter} from "react-router-dom";

const fetchLogInfo= async(data) =>{
    try{
        const result = await getLoginInfo(data);
        if(result.status ===200){
        console.log("서버 데이터와 일치: "+ result.data ); // result의 반환값 확인
        return true;
        }
    } catch(e){
        console.log(e);
        alert("id와 비밀번호를 확인해주세요!");
        return false;
    }
}

const Login = () => {

  const [authenticated,setAuthenticated] = useState(false);
  const onFinish = async (values)=> {
      console.log('Received values of form: ', values);
      const isAuth = await fetchLogInfo(values);
      sessionStorage.setItem("isAuth", isAuth); //세션 스토리지 저장
      sessionStorage.setItem("id",values.userid);

      setAuthenticated(isAuth);
    }
      if(authenticated){
        // history.push('/Home');
        return <Redirect to="/Home"/>
      }else{
        return <LoginForm onFinish={onFinish} >
               </LoginForm>
      }
};

export default withRouter(Login);