wcamarao / session.socket.io

Express/connect session integration with socket.io
351 stars 52 forks source link

You can't directly work with session when you're using connect-mongo store #39

Open terrasoff opened 10 years ago

terrasoff commented 10 years ago

ok, i setup session.socket.io and my socket is working. But working with session i got javascript object instead of mongo record. So i can't perform this code (as shown):

sessionSockets.on('connection', function (err, socket, session) {
  session.foo = 'bar';
  //at this point the value is not yet saved into the session
  session.save();
  //now you can read session.foo from your express routes or connect middlewares
});

Becouse of you get unserialized record:

https://github.com/kcbanner/connect-mongo/blob/master/lib/connect-mongo.js

MongoStore.prototype.get = function(sid, callback) {
    var self = this;
    this._get_collection(function(collection) {    
      collection.findOne({_id: sid}, function(err, session) {
        try {
          if (err) {
            callback && callback(err, null);
          } else {      

            if (session) {
              if (!session.expires || new Date < session.expires) {
                callback(null, self._unserialize_session(session.session));
...
wcamarao commented 9 years ago

Is this still an issue / have you found a solution?

jdutriaux commented 9 years ago

I get an undefined session with connect-mongo.

Any idead where the issue is?

jhereu commented 9 years ago

@MrHalfman are you using Sails with the connect-mongo module? I've a Sails app with that module too and I'm struggling with the socket.io sessions...

Furthermore, are you using passport?

wcamarao commented 9 years ago

Keep in mind if you're using socket.io >= 1.0 you don't need this module anymore. There's a simpler way in the readme file. Otherwise feel free to send PR's as needed.