console.log( 'before await' );
await new Promise(async(resolve, reject) => {
console.log( 'before await 2' );
await dbConnection.query('SELECT * FROM users WHERE name = ? AND password = ?', [username, password], function(err, results, fields) {
console.log( 'begin callback' );
if (!err) {
console.log( 'no error branch', results );
// If there is an issue with the query, output the error
// If the account exists
resolve(results);
console.log( 'after resolve', results.length );
if (results.length > 0) {
// Authenticate the user
req.session.loggedin = true;
req.session.username = username;
// Redirect to home page
res.send(`Вы вошли под именем ${username}`);
} else {
res.send('Неправильный пароль или имя пользователя');
}
res.end();
} else {
console.log( 'has error branch', err );
reject(err);
}
});
});
console.log( 'after await' );