I am trying to regnerate session on successful validation of user credentials.But the session doesn't get regenerated when the code is in db callback
app.post('/login',function(req,res){
var userName=req.body.userid.toLowerCase();
db.collection('credentials').findOne({'userName':userName},function(err,result){
req.session.regenerate(function (err) {
});
});
});
It works fine out side it
app.post('/login',function(req,res){
var userName=req.body.userid.toLowerCase();
req.session.regenerate(function (err) {
});
db.collection('credentials').findOne({'userName':userName},function(err,result){
});
});
Any ideas?
Looks like the mistake was on my part.The code was responding to the request right below the code i posted. Since these work in async, I guess the response was sent beofre the session was reset.
app.post('/login',function(req,res){
var userName=req.body.userid.toLowerCase();
db.collection('credentials').findOne({'userName':userName},function(err,result){
req.session.regenerate(function (err) {
});
res.send('welcome '+result.firstName+' '+result.lastName);
});
});
I moved the response inside the regenarte call back and it is working now.