Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

socket.io sessions don't seem to work in 0.8.9-pre #289

Closed
mikermcneil opened this Issue Apr 2, 2013 · 3 comments

Comments

Projects
None yet
2 participants
Owner

mikermcneil commented Apr 2, 2013

/code/sails/node_modules/connect/lib/middleware/session/session.js:83
  this.req.sessionStore.set(this.id, this, fn || function(){});
                        ^
TypeError: Cannot call method 'set' of undefined
    at Session.save (/code/sails/node_modules/connect/lib/middleware/session/session.js:83:25)
    at Object.exports.session.link (/code/enlyton/api/services/AuthenticationService.js:73:31)
    at /code/enlyton/api/controllers/auth/login.js:29:35
    at /code/sails/lib/waterline/deferredObject.js:167:12
    at /code/sails/node_modules/async/lib/async.js:116:25
    at promiseCallback (/code/sails/lib/waterline/deferredObject.js:162:13)
    at /code/sails/lib/waterline/collection.js:705:10
    at /code/sails/lib/waterline/adapter.js:206:16
    at Quit._callback (/code/enlyton/node_modules/sails-mysql/MySQLAdapter.js:616:12)
    at Quit.Sequence.end (/code/enlyton/node_modules/sails-mysql/node_modules/mysql/lib/protocol/sequences/Sequence.js:66:24)
Owner

mikermcneil commented Apr 2, 2013

If you create a new project and run sails generate controller auth, then paste in the following:

/*---------------------
    :: Auth 
    -> controller
---------------------*/
var AuthController = {

    index: function (req,res) {

        var val = req.session.test;

        req.session.test = "foo";
        req.session.save();

        res.view({
            original: val,
            newVal: req.session.test
        });
    }

};
module.exports = AuthController;

Create a folder /views/auth and the file /views/auth/index.ejs with contents:


<h1>Current:<%= newVal %> </h1>
<h1>Original:<%= original %> </h1>

Then visit http://localhost:1337, and run the following in the console:

var socket = io.connect('http://localhost:1337')
socket.request('/auth',{},function (resp){console.log(resp);});

The server will crash with:

/code/sails/node_modules/connect/lib/middleware/session/session.js:83
  this.req.sessionStore.set(this.id, this, fn || function(){});
                        ^
TypeError: Cannot call method 'set' of undefined
    at Session.save (/code/sails/node_modules/connect/lib/middleware/session/session.js:83:25)
    at AuthController.index (/Users/mike/sandbox/asdg/api/controllers/AuthController.js:12:15)
    at runHandler (/code/sails/lib/router.js:375:2)
    at afterThat (/code/sails/lib/router.js:316:18)
    at /code/sails/lib/router.js:356:46
    at Glob.<anonymous> (/code/sails/node_modules/glob/glob.js:91:7)
    at Glob.EventEmitter.emit (events.js:95:17)
    at Glob._processEmitQueue (/code/sails/node_modules/glob/glob.js:272:10)
    at Glob.emitMatch (/code/sails/node_modules/glob/glob.js:257:8)
    at Glob._finish (/code/sails/node_modules/glob/glob.js:219:8)

I believe this has to do with the concern I expressed here:
#259 (comment)

Thanks!
Mike

@ghost ghost assigned techpines Apr 2, 2013

Member

techpines commented Apr 2, 2013

@mikermcneil Yea that will break it. You should be able to get a handle to sessionStore without throwing it in with the socket data.

Member

techpines commented Apr 2, 2013

Probably just need to attach sessionStore to req in a different way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment