title: passport.socketio's passport "Failed to deserialize user out of session". But passport in my main app (with the same key) deserializes just fine
body: <p>passport.socketio throwing this error, while failing to authorize the user.</p>
  
  <blockquote>
    <p>Error: Error: Failed to deserialize user out of session</p>
  </blockquote>
  
  <p>I've narrowed the problem down to passport.socketio's <a href="https://github.com/jfromaniello/passport.socketio/blob/master/lib/index.js" rel="nofollow noreferrer"><code>/lib/index.js</code></a>.</p>
  
  <p>At line 59 </p>
  
  <pre><code>  auth.passport.deserializeUser(userKey, function(err, user) {
      if (err)
        return auth.fail(data, err, true, accept);
      ...
  </code></pre>
  
  <p>It throws that error. Debugger tells me the <code>userKey</code> is valid, and <em>should</em> deserialize the user. It's the <strong>same key</strong> that passport in my main app uses to deserialize the user. (it's the ID of mongoDB object). And passport in my main app has no problem deserializing the user. (<a href="https://stackoverflow.com/revisions/23492459/9">details</a>) 
  So don't know why this still throws the error. </p>
  
  <p>The <code>userKey</code> passed here is the same key passport in my main app uses to deserialize. </p>
  
  <p>I've gone to the extent of making the <code>userKey</code> global and putting it in my main code</p>
  
  <pre><code>  passport.deserializeUser(global.userKey, function(err, user) {
      if (err)
        return auth.fail(data, err, true, accept);
      console.log('ok');
  </code></pre>
  
  <p>Which results in infinite loop (because it's inside outer passport.deserialize) but iut prints 'ok'!, so passport from my main app can atleast deserialize just fine using the same thing that passport from index.js (passport.socketio\lib\index.js) can not! .. for some reason.</p>
  
  <p>Then I've even tried passing the passport object itself from main app </p>
  
  <pre><code>io.set('authorization', require('passport.socketio').authorize({
      passport: passport,
      ...
  </code></pre>
  
  <p>which actually results in no errors!! but then I don't get the <code>socket.handshake</code> object.</p>
  
  <p>I'm out of ideas to diagnose this any further and would really appreciate any help whatsoever. </p>
  
  <p>What could be causing <code>passport.socketio</code>'s <code>passport</code> to not "deserialize user out of session"?</p>