fix(striker-ui-api): add /auth/logout

main
Tsu-ba-me 2 years ago
parent ffe3c0853f
commit a4524b6d27
  1. 1
      striker-ui-api/src/lib/request_handlers/auth/index.ts
  2. 17
      striker-ui-api/src/lib/request_handlers/auth/logout.ts
  3. 7
      striker-ui-api/src/routes/auth.ts

@ -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…
Cancel
Save