SignInContainer.js
1.19 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
42
43
44
45
46
47
import React, { useContext } from 'react';
import { withRouter } from 'react-router-dom';
import { SignApi } from '../../utils/api';
import userContext from '../../utils/context';
import FormField from '../../components/signin/FormField';
import { pathUri } from '../../constants/path';
const SignInContainer = (props) => {
const { history } = props;
const { data, setData } = useContext(userContext);
const login = async (state) => {
const data = {
email: state.email,
password: state.password,
};
try {
const { user } = await SignApi('http://localhost:9000/auth/login', { data });
handleSuccess(user);
} catch(err) {
console.log(err);
}
}
const guestLogin = () => {
history.push(pathUri.editor);
}
const handleSuccess = (user) => {
setData({
...data, userName: user.name
})
history.push(pathUri.board);
};
return (
<>
<FormField
loginState={true}
login={login}
guestLogin={guestLogin}
/>
</>
);
};
export default withRouter(SignInContainer);