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

예진언니 menu 요청 적용

parent f54a6948
...@@ -8,11 +8,12 @@ const Nav = styled.nav` ...@@ -8,11 +8,12 @@ const Nav = styled.nav`
function Menu() { function Menu() {
const [state, setState] = useState() const [state, setState] = useState()
const name = localStorage.getItem('name');
if (state) return <Redirect to="/" />; if (state) return <Redirect to="/" />;
function logout() { function logout() {
localStorage.removeItem('token'); localStorage.clear();
alert("로그아웃 되었습니다."); alert("로그아웃 되었습니다.");
setState(true); setState(true);
} }
...@@ -39,6 +40,7 @@ function Menu() { ...@@ -39,6 +40,7 @@ function Menu() {
</li> </li>
</ul> </ul>
<div> <div>
<div>{name} 안녕하세요.</div>
<button onClick={logout} type="button">로그아웃</button> <button onClick={logout} type="button">로그아웃</button>
<button><Link to="/signup">회원가입</Link></button> <button><Link to="/signup">회원가입</Link></button>
</div> </div>
......
...@@ -44,10 +44,9 @@ function Login() { ...@@ -44,10 +44,9 @@ function Login() {
data: values, data: values,
}).then(res => { }).then(res => {
if (res.status === 404) return alert(res.data.error) if (res.status === 404) return alert(res.data.error)
alert("로그인이 완료되었습니다!")
localStorage.setItem('token', res.data.token); localStorage.setItem('token', res.data.token);
localStorage.setItem('id', res.data.users._id); localStorage.setItem('id', res.data.users._id);
localStorage.setItem('name', res.data.users.name);
setState(true); setState(true);
}) })
.catch(err => { .catch(err => {
......
...@@ -20,7 +20,7 @@ router.get('/', function (req, res, next) { ...@@ -20,7 +20,7 @@ router.get('/', function (req, res, next) {
router.post('/', function (req, res, next) { router.post('/', function (req, res, next) {
console.log('/login post request', req.body) 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 (err) return res.status(500).json({ error: err });
if (!users) { 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