Login.js
1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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){
if(authenticated){
// history.push('/Home');
return <Redirect to="/home"/>
}else{
return <LoginForm onFinish={onFinish} >
</LoginForm>
}
};
export default withRouter(Login);