-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
13 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,44 +8,37 @@ import { userInfoAtom } from '../../../atoms/UserAtom'; | |
import LoginForm from '../../../components/Login/LoginForm'; | ||
|
||
const LoginPage = () => { | ||
const [initData, setInitData] = useState({ | ||
email: '[email protected]', | ||
password: 'bc12345', | ||
}); | ||
const [message, setMessage] = useState(''); | ||
const [userInfo, setUserInfo] = useRecoilState(userInfoAtom); | ||
const setLogin = useSetRecoilState(loginAtom); | ||
|
||
const navigate = useNavigate(); | ||
|
||
const handleLogin = async (e) => { | ||
e.preventDefault(); | ||
const handleLogin = async (formData) => { | ||
try { | ||
const res = await postUserLogin(initData); | ||
const res = await postUserLogin(formData); | ||
if (res.status === 422) { | ||
setMessage(res.message); | ||
} else { | ||
setUserInfo({ | ||
...userInfo, | ||
account: res.user.accountname, | ||
profileImg: res.user.image, | ||
username: res.user.username, | ||
intro: res.user.intro, | ||
}); | ||
setLogin(true); | ||
localStorage.setItem('token', res.user.token); | ||
navigate('/home'); | ||
...userInfo, | ||
account: res.user.accountname, | ||
profileImg: res.user.image, | ||
username: res.user.username, | ||
intro: res.user.intro, | ||
}); | ||
setLogin(true); | ||
localStorage.setItem('token', res.user.token); | ||
navigate('/home'); | ||
} | ||
} catch (error) | ||
{ | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
}; | ||
|
||
return ( | ||
<Container> | ||
<Title>로그인</Title> | ||
<LoginForm handleLogin={handleLogin} initData={initData} setInitData={setInitData} message={message} /> | ||
<LoginForm handleLogin={handleLogin} message={message} /> | ||
<Signup to="/signup">이메일로 회원가입</Signup> | ||
</Container> | ||
); | ||
|