Reputation: 4578
When calling my User.create
method in my Sails.js app, I get the following error:
/Users/user/code/bt/tgein/node_modules/mongodb-core/lib/topologies/server.js:779 catch(err) { process.nextTick(function() { throw err}); }
Here is my User controller in its entirety.
User.create(req.params.all(), function userCreated(err, user) {
// var userid = user.id;
// console.log(userid);
if(err) {
console.log(err);
req.session.flash = {
err: err.ValidationError
}
return res.redirect('/user/loginDetails');
}
var oldDateObj = new Date();
var newDateObj = new Date(oldDateObj.getTime() + 60000);
req.session.cookie.expires = newDateObj;
req.session.authenticated = true;
console.log(req.session);
// res.redirect('/user/profileSelection/?id=' + user.id);
// Saves user data into session variable
req.session.user = user;
res.redirect('/user/profileSelection/');
});
apparently the session value is undefined for the request. This seems symptomatic of something basic that isn't happening, but I don't know what that is.
Upvotes: 1
Views: 15145
Reputation: 4578
The problem was I had the session store trying to go through the production adapter in my sessions.js
on my local app, which caused the req.session
to fail.
Upvotes: 0
Reputation: 6760
I think the problem is not of session, as session is always retained/defined within an sails app. May be the issue exists, when you trying to save the data.
Upvotes: 1
Reputation: 3536
req.session.cookie
is not defined and you are trying to set a value to an undefined object.
var oldDateObj = new Date();
var newDateObj = new Date(oldDateObj.getTime() + 60000);
if(!req.session.cookie)
req.session.cookie = {};
req.session.cookie.expires = newDateObj;
Upvotes: 1