Answer the question
In order to leave comments, you need to log in
How to write data to session when working with socket.io Node.js?
I started rewriting Ajax requests for sockets, and ran into a problem, let's say I'm doing authorization through a socket, and in case of successful authorization, I need to write the user id to the session, with ajax there was a request in which there was access to the request.session session, but when processing requests for there is no request on sockets, and how do I access the session?
io.on('connection', function(client){
client.on('login', function (data) {
console.log(data);
if (data.Login && data.Password)
{
mysql.select("SELECT id FROM users where md5(Login) = md5(?) and Password = md5(?)", [data.Login, data.Password], function (user) {
if (user.err) client.emit('finishlogin', {result:'err', message:'Произошла ошибка попробуйте позже'});
else {
if (user.result.length == 0) client.emit('finishlogin', {result:'err', message:'Не правильный логин или пароль'});
else {
client.emit('finishlogin', {result:'ok', message:''});
/*
Тут записать в сессию данные
*/
}
}
});
}
});
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question