node.js sessionStore shows the same data for all sessions
I use node.js and want to store sessions in a KeyValue store. I tried Redis and MongoDB for this. In both cases I use the variable req.sessionStore for this, as in this example:
app.get('/user', parseParams, function(req,res) {
data = req.sessionStore.userData || {};
sendStringified(req,res,data);
});
But no matter in which browser I open my webapp, if I go to the site, it accesses the data of the last account I logged in from somewhere else. So only one user can be logged in at the same time. It seems to share the req.sessionData object over all sessions. Am I missing something?
If I go to my session db in the mongo client, and do a db.sesions.find(), it shows entries in this format:
{ "_id" : "CKMF8DfBpYNSCNyPIDj9ozVM.ZVo4d0/Oxrxdql44E6QL+U1AgtHWbGXLyX826YO1bDo",
"session" : "{\"lastAccess\":1301358495277,
\"cookie\":{\"originalMaxAge\":14400000,\"expires\":\"2011-03-29T04:28:16.004Z\",\"httpOnly\":true,开发者_StackOverflow中文版\"path\":\"/\"},
\"oauth\":{\"token\":\"the_token\",\"token_secret\":\"the_secret\",\"verifier\":\"the _verifier\",\"access_token\":\"a_token\",\"access_token_secret\":\"a_t_s\"}}" }
I'm guessing your are using connect or express, so:
You don't interact with the stores directly. You just interact with req.session
, and connect will use the store you configured.
I recommend you to take a look on the example provided on the rmongo store (the redis example was removed).
https://github.com/masylum/connect-mongodb/blob/master/examples/index.js
精彩评论