Node.js client.emit only working after first try?
I am writing an app where I have a user login via an email and password. I
have my node.js server return either a 'yes' or 'no' if the login is
correct.
On the server, I can console.log the result and see it every time.
However, the client.emit command only works after the first time. AND only
if the inputs 'email' and 'password' are identical for both of those
times. So the alert on the client is only firing after the second time.
Here is my server code:
client.on('checkcred', function(email, password){
helper.check(email, password,function(run){
client.emit('conf',run);
console.log(run);
});
});
helper.js
exports.check = function(zmail, pasword,callback){
client.query('SELECT id FROM passwords WHERE
email="'+zmail+'"', function(err,data){
if(data.length == 0){
console.log("wrong email");
callback("no");
}else{
var savedemail = data[0].id;
client.query('SELECT password FROM passwords WHERE
id='+savedemail+'', function(err,pass){
var databasepass = pass[0].password;
if (pasword == databasepass){
console.log("correct pass");
callback("yes");
}else{
console.log("incorrectpass");
callback("no");
}
});
}
});
}
client
var socket = io.connect('http://54.213.92.113:8080');
socket.on('conf', function (yn) {
alert(yn);
});
function upload(email, password){
//check the email and password against the saved email and pass.
socket.emit('checkcred', email, password);
}
I would really appreciate any help!
No comments:
Post a Comment