使用filestore时如何完全销毁/清除express中的当前会话

时间:2017-01-05 18:02:06

标签: javascript node.js session express

这是我在node.js中的注销代码:

    export function logout(req, res) {
       var logoutUrl = authServer + '/1.0/Account/Logout';
       var thisReq = req;
       var thisRes = res;
       request({
         method: 'GET',
         url : logoutUrl
       },
        function (error, response, body) {
         thisReq.session.destroy();
         thisReq.session.user = null;
         thisReq.session = null;
         thisRes.clearCookie('connect.sid', { path: '/' });
      }).pipe(res);
   }

执行上面的代码后,在另一个路由文件中,我正在检查这个..

function isAuthenticated(req, res, next) {
  if (req.session.user) {
    console.log('Session user FOUND_______________________________________');
    return next();
  } 
  console.log('No Session user FOUND!_______________________________________');

  return res.send(401, 'No current user found in the session');
}

虽然在执行注销后,我仍然看到“Session user Found ....”消息被记录到控制台。

以下是我如何配置快速会话文件存储..

var fileStoreOptions = {};
  app.use(session({
    store: new FileStore(fileStoreOptions),
    secret: 'keyboard cat',
    resave: true,
    saveUninitialized: true
  }));

0 个答案:

没有答案