I am trying to use express-session
for session management. It works okay inside functions I create, but inside socket.io
it doesn't work at all.
Here's what I have:
socket.on('chat_message', function(message, req) {
if (req.session.lang) {
translate(message, null, req.session.lang, true).then(res => {
console.log(res.translation);
io.to(socket.id).emit('chat_message', '<strong>p' + socket.username + '</strong>: ' + res.translation);
}).catch(err => {
console.error(err);
});
}
});
})
it is giving me the error:
TypeError: Cannot read property 'session' of undefined
on the if statement line: if (req.session.lang) {
why isn't this working? I have express-session defined as well.