title: Socket.io - Implementing a user-socket association map for private messaging
body: <p>I'm trying to create a private messaging system using socket.io</p>
  
  <p>In order to associate the users with their sockets, most sites are suggesting something like this:</p>
  
  <pre><code>var people = {};
  
  client.on('connection', function(socket) {
  
      //join the server
      socket.on('add user', function(user_id) {
          //create user-socket map
          people[user_id] = socket.id;
      });
  
  });
  </code></pre>
  
  <p>In my opinion, the problem with the above code is that the <code>user_id</code> is sent from the client side, so if the user somehow modify it and send another <code>user_id</code> an impersonation will take place. </p>
  
  <p>Also, I can't access <code>req.user._id</code> under <code>client.on('connection'...</code> so how am I supposed to get the <code>user_id</code> from the server's side? I'm using node.js, passport and express.</p>