function login(email, password, callback) {
var connection = mysql({
host: ‘localhost’,
user: ‘’,
password: ‘’,
database: ‘’
});
connection.connect();
var query = "SELECT id, nickname, email, password " +
“FROM users WHERE email = ?”;
connection.query(query, [email], function (err, results) {
if (err) return callback(err);
if (results.length === 0) return callback(new WrongUsernameOrPasswordError(email));
var user = results[0];
bcrypt.compare(password, user.password, function (err, isValid) {
if (err) {
callback(err);
} else if (!isValid) {
callback(new WrongUsernameOrPasswordError(email));
} else {
callback(null, {
id: user.id.toString(),
nickname: user.nickname,
email: user.email
});
}
});
});
}
That’s the generated code from ‘Connections > Database > Custom Database’ when setting up the database connection. Unlike in the code above, I have set values for user, password and database. When I try to save the settings, I get an error saying “Line 16: ‘WrongUsernameOrPasswordError’ is not defined” and “Line 23: ‘WrongUsernameOrPasswordError’ is not defined”. Moreover, if I try to test the connect by logging in with a user in the database, I get another error saying “connect ECONNREFUSED 127.0.0.1:3306”.
Thanks for the reply. Sorry about the long message, I am really desperate to solve this issue as my final year university project depends on it. Please let me know if you would like to see screenshots.