Skip to content

Commit

Permalink
♻️ Refactor: 로그인 컴포넌트화 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
sy-paik committed Oct 30, 2023
1 parent 90e00f0 commit 95d9081
Showing 1 changed file with 13 additions and 20 deletions.
33 changes: 13 additions & 20 deletions src/pages/LoginPage/LoginPage/LoginPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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>
);
Expand Down

0 comments on commit 95d9081

Please sign in to comment.