var name = socket.handshake.session.user;
TypeError: Cannot read property 'user' of undefined
这是显示的错误内容,我在用户登入时有
exports.reg = function(req, res){
var User = require('../models/user.js');
var newUser = new User({
name: req.body.username,
password: req.body.password,
});
User.get(req.body.username,function(err, password){
if(!password){
return res.redirect('/');
}
if(password != req.body.password){
return res.redirect('/');
}else{
req.session.user = newUser;
res.redirect('/talk');
}
})
};
有让req.session.user = newUser;
并且立刻console.log(req.session.user)是可以调用的,可是为什么在socket.io中的io.sockets.on('connection', function (socket)
中显示如上错误?