I searched and found a lot of similar problems with session variable being set to undefined, but none of the answers I found seemed applicable.
I have this function in my router file:
exports.loginHandler = function(req, res){
username = req.body.username;
password = req.body.password;
readAccount(username, function(acct){
if (acct.password = password){
req.session.username = username;
console.log(username+' logged in'+' pass: '+acct.password);
};
});
res.redirect('/');
};
console.log executes just fine and both username and acct.password have the appropriate values. However, req.session.username just ends up being set to undefined.
Here's the readAccount function:
readAccount = function(user, callback){
AM.login(user, function(acct){
callback(acct);
});
};
And here's AM.login:
exports.login = function(user, callback){
accounts.findOne({username: user}, function(err, result){
if (err) throw err;
callback(result);
})
}
I'm guessing session variables can't be set under conditions, since this type of error doesn't seem uncommon.