I m using express-session
and memcached-connect
package for maintaining session.
Everything is working as expected.
Here is my implementation:
Middleware
app.use(session({
rolling: true,
secret: 'iloveexpress',
proxy: 'true',
store: new MemcachedStore({
hosts: ['127.0.0.1:11211']
}),
cookie: {
maxAge: 86400000,
path: "/",
domain: 'example.com'
}, //1 Day
saveUninitialized: false,
resave: true
}));
Setting Session
req.session.data = {
id: '123,
name: 'ABC',
amount: 1000,
profilePic: '/images/asd.jpg'
}
Updating Session
req.session.data.amount = 500;
But when I update a particular data in the session, it not updating. The other time I make a request to the Api its showing the old data, i.e., amount = 1000;
EDIT:
console of req.session
Session {
cookie:
{ path: '/',
_expires: 2017-09-20T07:11:35.394Z,
originalMaxAge: 86399951,
httpOnly: true,
domain: 'example.com' },
data:
{ id: '591173362ad30b419e2c4f54',
name: 'ABC',
amount: 1000,
profilePic: '/image/1496663576532Koala.jpg' } }
2
Answers
I know it’s an old one, but I had the same problem and fixed it by setting the cookie option :
secure: true
Hey I don’t If this applies in your case but if you are updating the session variables in the post method use:
req.session.save()
after updating the variable