Skip to content

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

@terrasoff

Description

@terrasoff

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));
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions