0

I am trying to store and update a single var on a sessionCookie. The session object is only updated if i force an error immediately after. If i try to use as documented, the value I set is undefined when I try to access it elsewhere

package:

 "dependencies": {
  "express": "3.2.1"
 },
 "engines": {
  "node": "0.10.5",
  "npm": "1.2.18"
 }

setup:

app.use( express.bodyParser() );
app.use( express.methodOverride() );
app.use( express.cookieParser('secret') );
app.use( express.cookieSession(  ) );

routes:

module.exports.size = function ( req, res ) {
   req.session["size"] = req.body.size;
   req.s["size"] =  req.body.size; // force to error: this updates session props
};

module.exports.pages = function ( wwwPath, imageEndPoint, isDebug ) {
   return  function ( req, res ) {
       var size = req.session["size"] // is undefined unless above forced to error
   }
}
neil manuell
  • 225
  • 2
  • 10
  • OK, so I think I might have found the answer... I have to send something for them to be updated, yes? So if I throw an error express will send a response, thus writing to the cookie http://stackoverflow.com/questions/12197053/express-cookie-return-undefined?rq=1. I'm just seeing if this will fix it – neil manuell Jun 29 '14 at 09:04

1 Answers1

0

Ok so I wasn't sending a response, so the cookie wasn't being updated. When an error was forced express sent an error message, causing the cookie to be updated.

see answer below:

express cookie return undefined

rubber ducking

Community
  • 1
  • 1
neil manuell
  • 225
  • 2
  • 10