0

session was store in mongodb. When the user get to the website.But I can't get the session value

var cookieParser=require("cookie-parser");
var signedCookieParser=cookieParser("technode");
var sessionStore=new MongoStore({url:"mongodb://localhost/technode"});

io.set('authorization', function(handshakeData, accept) {
    //console.log(handshakeData.headers);

  signedCookieParser(handshakeData, {}, function(err) {
    if (err) {
      accept(err, false)
    } else {
      sessionStore.get(handshakeData.signedCookies['connect.sid'], function(err, session) {
        if (err) {
          accept(err.message, false)
        } else {
          handshakeData.session = session;
          console.log(handshakeData.session);   //But I can't get the value
          if (session) {
            accept(null, true)
          } else {
            accept('No login')
          }
        }
      })
    }
  })
  accept(null,true);    
})

I want to print the handshakeData.session.But it turn to "undefined"

X Rene
  • 419
  • 2
  • 7
  • The question should really be "how can I get session value ***set by Express*** in socket" which has been answered before: [How to share sessions with Socket.IO 1.x and Express 4.x?](http://stackoverflow.com/questions/25532692/how-to-share-sessions-with-socket-io-1-x-and-express-4-x) – laggingreflex Jun 30 '15 at 02:28
  • @laggingreflex well.Why didn't my solution work? – X Rene Jun 30 '15 at 02:56

0 Answers0