Skip to content

Commit

Permalink
Logout route.
Browse files Browse the repository at this point in the history
  • Loading branch information
queerviolet committed Nov 2, 2016
1 parent 4115d94 commit d47b47b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
4 changes: 4 additions & 0 deletions server/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ auth.post('/:strategy/login', (req, res, next) =>
})(req, res, next)
)

auth.post('/logout', (req, res, next) => {
req.logout()
res.redirect('/api/auth/whoami')
})

module.exports = auth

21 changes: 20 additions & 1 deletion server/auth.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('/api/auth', () => {
.then(res => expect(res.body).to.contain({
email: alice.username
}))
)
)
})

it('when not logged in, responds with an empty object', () =>
Expand All @@ -61,4 +61,23 @@ describe('/api/auth', () => {
.then(res => expect(res.body).to.eql({}))
)
})

describe('POST /logout when logged in', () => {
const agent = request.agent(app)

before('log in', () => agent
.post('/api/auth/local/login')
.send(alice))

it('logs you out and redirects to whoami', () => agent
.post('/api/auth/logout')
.expect(302)
.expect('Location', '/api/auth/whoami')
.then(() =>
agent.get('/api/auth/whoami')
.expect(200)
.then(rsp => expect(rsp.body).eql({}))
)
)
})
})

0 comments on commit d47b47b

Please sign in to comment.