Commit 7b01b433 authored by CHAERIN KIM's avatar CHAERIN KIM
Browse files

예진언니 menu 요청 적용

parent f54a6948
......@@ -8,11 +8,12 @@ const Nav = styled.nav`
function Menu() {
const [state, setState] = useState()
const name = localStorage.getItem('name');
if (state) return <Redirect to="/" />;
function logout() {
localStorage.removeItem('token');
localStorage.clear();
alert("로그아웃 되었습니다.");
setState(true);
}
......@@ -39,6 +40,7 @@ function Menu() {
</li>
</ul>
<div>
<div>{name} 안녕하세요.</div>
<button onClick={logout} type="button">로그아웃</button>
<button><Link to="/signup">회원가입</Link></button>
</div>
......
......@@ -44,10 +44,9 @@ function Login() {
data: values,
}).then(res => {
if (res.status === 404) return alert(res.data.error)
alert("로그인이 완료되었습니다!")
localStorage.setItem('token', res.data.token);
localStorage.setItem('id', res.data.users._id);
localStorage.setItem('name', res.data.users.name);
setState(true);
})
.catch(err => {
......
......@@ -20,7 +20,7 @@ router.get('/', function (req, res, next) {
router.post('/', function (req, res, next) {
console.log('/login post request', req.body)
User.findOne({ id: req.body.id }, 'id password', function (err, users) {
User.findOne({ id: req.body.id }, 'id password name', function (err, users) {
if (err) return res.status(500).json({ error: err });
if (!users) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment