title: how to make to disconect event fires only when users log out from account (node.js + express+ socket.io)
body: <p>I have a function to go out from account: </p>
  
  <pre><code>exports.logout = function(req,res){
      req.session.destroy( err =&gt; {
          if(err)
              console.log(err);
         res.redirect("/login");
      });
   };
  </code></pre>
  
  <p>To use socket.io and express together I have a middleware:</p>
  
  <pre><code>io.use(function(socket, next) {
    sessionMiddleWare(socket.request, socket.request.res, next);
  });
  </code></pre>
  
  <p>And I have function where I use socket.io. I need to disconect event fires only when user log out from application. But now my disconect event is emit always when I refresh a page: </p>
  
  <pre><code>exports.someFunction = function (io) {
  
      io.on('connection', function(socket){
          console.log(`Client connected socketId = ${socket.id}`);
          console.log("session_id: " + socket.request.session.session_id);
          usersMap.set(socket.request.session.session_id, socket.id);
  
         });
            socket.on('disconnect', function(){
               usersMap.delete(socket.request.session.session_id);
               console.log('user disconnected');
               console.log("Map size: " + usersMap.size);     
            });
          });
  };
  </code></pre>
  
  <p>Please help, how to make to disconect event fires only when users log out from account. Sorry for my English. </p>