Toggle navigation
Toggle navigation
This project
Loading...
Sign in
박민정
/
We-Shop
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
박민정
2021-06-03 23:57:15 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
80003fa6418cbc03b4d8987316963465d6d0e8ae
80003fa6
1 parent
c1098b51
[feat] logout
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
2 deletions
boiler-plate/index.js
boiler-plate/index.js
View file @
80003fa
...
...
@@ -53,7 +53,7 @@ app.post('/api/users/register', (req, res) => {
})
// 로그인 구현
// 로그인 구현
-> 로그인 하면 토큰 생성
app
.
post
(
'/api/users/login'
,
(
req
,
res
)
=>
{
// 1. 요청된 이메일이 데이터베이스에 있는지 찾기
User
.
findOne
({
email
:
req
.
body
.
email
},
(
err
,
user
)
=>
{
...
...
@@ -82,7 +82,7 @@ app.post('/api/users/login', (req, res) => {
})
//
//
인증 구현 (이 사람이 일반유저인지 관리자인지)
app
.
get
(
'/api/users/auth'
,
auth
,(
req
,
res
)
=>
{
// 여기까지 미들웨어(auth) 통과했으면 authentication == true 라는 뜻
res
.
status
(
200
).
json
({
...
...
@@ -96,6 +96,17 @@ app.get('/api/users/auth', auth ,(req,res) => {
})
})
// 로그아웃 구현 (로그인 때 만든 토큰을 지워버림)
app
.
get
(
'/api/users/logout'
,
auth
,
(
req
,
res
)
=>
{
User
.
findOneAndUpdate
({
_id
:
req
.
user
.
_id
},
// id로 User를 찾아서 업데이터 시킴
{
token
:
""
},
(
err
,
user
)
=>
{
if
(
err
)
return
res
.
json
({
success
:
false
,
err
});
return
res
.
status
(
200
).
send
({
success
:
true
})
})
})
app
.
listen
(
port
,
()
=>
{
console
.
log
(
`Example app listening at http://localhost:
${
port
}
`
)
})
...
...
Please
register
or
login
to post a comment