moscajs / mosca

MQTT broker as a module
mosca.io
3.2k stars 513 forks source link

In aedes.authenticate function callback(error, authorized) is not invoking aedes.on('clientError', function (client, err) when error is passed or My coding is wrong? #646

Closed rezwanul7 closed 7 years ago

rezwanul7 commented 7 years ago

aedes.authenticate = function (client, email, password, callback) { console.log("client waiting for authentication " + client.id); User.getUser(email, function (err, rows) { var authorized = false; var error = null; if (err) { error = new Error('Server unavailable'); error.returnCode = 3; console.log("mysql server Error " + err.code); } else { if (rows.length > 0) { var hashedPassword = rows[0].password; bcrypt.compare(password, hashedPassword, function (err, res) { if (res) { authorized = true; client.user = email; console.log("authentication success."); } else { error = new Error('Auth error'); error.returnCode = 4; console.log('wrong authentication info provided ' + client.id + " using " + email); } }); } else { console.log("user not found "); } } console.log("calling call back"); callback(error, authorized); }); };

aedes.on('clientError', function (client, err) { console.log('client error', client.id, err.message); // ,err.stack });

mcollina commented 7 years ago

Feel free to open this on the aedes repo.