I know that I can use
function(req, res) {
req.session
}
using express. However I need to access the session outside of the response function. How would I go about doing that?
I’m using socket.io to pass information for adding posts and comments. So when I receive the socket.io message on the server-side, I need to verify the person posting the information by using the session. However since this is being done via socket.io there is no req/res.
Using socket.io, I’ve done this in a simple way. I assume you have an object for your application let’s say MrBojangle, for mine it’s called Shished:
Then on your authorization method, I’m using MongoDB for session storage:
Then before saving a record in the model, you can do:
model._author = shished.getHandshakeValue( socket, 'userId' );