parent
ffe3c0853f
commit
a4524b6d27
3 changed files with 23 additions and 2 deletions
@ -1 +1,2 @@ |
||||
export * from './login'; |
||||
export * from './logout'; |
||||
|
@ -0,0 +1,17 @@ |
||||
import { RequestHandler } from 'express'; |
||||
|
||||
import { stdout } from '../../shell'; |
||||
|
||||
export const logout: RequestHandler = (request, response) => { |
||||
request.session.destroy((error) => { |
||||
let scode = 204; |
||||
|
||||
if (error) { |
||||
scode = 500; |
||||
|
||||
stdout(`Failed to destroy session upon logout; CAUSE: ${error}`); |
||||
} |
||||
|
||||
response.status(scode).send(); |
||||
}); |
||||
}; |
@ -1,10 +1,13 @@ |
||||
import express from 'express'; |
||||
|
||||
import { login } from '../lib/request_handlers/auth'; |
||||
import { assertAuthentication } from '../lib/assertAuthentication'; |
||||
import { login, logout } from '../lib/request_handlers/auth'; |
||||
import passport from '../passport'; |
||||
|
||||
const router = express.Router(); |
||||
|
||||
router.post('/login', passport.authenticate('login'), login); |
||||
router |
||||
.post('/login', passport.authenticate('login'), login) |
||||
.put('/logout', assertAuthentication(), logout); |
||||
|
||||
export default router; |
||||
|
Loading…
Reference in new issue