3 var env = require('gitter-web-env');
4 var winston = env.logger;
5 var nconf = env.config;
6 const asyncHandler = require('express-async-handler');
7 var rememberMe = require('./rememberme-middleware');
8 const oauthService = require('gitter-web-oauth');
9 const getAccessToken = require('../get-access-token-from-req');
11 var authCookieName = nconf.get('web:cookiePrefix') + 'auth';
12 var sessionCookieName = nconf.get('web:cookiePrefix') + 'session';
14 // This isn't actually a middleware, it's a useful function that
15 // should probably be put somewhere else
16 function logoutPreserveSession(req, res, next) {
19 var authCookie = req.cookies && req.cookies[authCookieName];
22 res.clearCookie(authCookieName, { domain: nconf.get('web:cookieDomain') });
24 return rememberMe.deleteRememberMeToken(authCookie, next);
30 module.exports = asyncHandler(async (req, res, next) => {
32 var userId = user && user.id;
33 var username = user && user.username;
35 winston.info('logout: logging out user', {
40 const accessToken = getAccessToken(req);
41 await oauthService.deleteToken(accessToken);
43 logoutPreserveSession(req, res, () => {
44 res.clearCookie(sessionCookieName, { domain: nconf.get('web:cookieDomain') });
46 req.session.destroy(function(err) {