title: Using Websocket with Passport
body: <p>How do I access the passport login for the current session when someone opens a WebSocket connection?  </p>
  
  <p>I've found a nice project <a href="https://www.npmjs.com/package/express-ws" rel="noreferrer">express-ws</a> which seems to work beautifully</p>
  
  <pre><code>app.ws('/', function(ws, req) {
      ws.on('message', function(msg) {
          console.log('express-ws --- ', msg);
      });
      console.log('socket', req.user); //current user == req.user
  });
  </code></pre>
  
  <p>But how would I go about getting this same information with a plain Websocket connection?</p>
  
  <pre><code>var WebSocketServer = require('ws').Server,
      wss = new WebSocketServer({ port: 3001 });
  
  wss.on('connection', function(socket){
      //Where is the current user????
      console.log('connection');
  
      socket.on('message', function(message){
          console.log('message received', message);
      });
  });
  </code></pre>
  
  <p>(this second connection does work just fine - but I can't for the life of me find any way to get the logged in info from Passport)</p>