When I use Login script in database action scripts, MySQL cannot be connected.
My node code is as follows:
function login(userName, password, callback) {
const mysql = require('mysql');
const bcrypt = require('bcrypt');
const azureCa = "...";
const connection = mysql.createConnection({
host: '...',
port: '3306',
user: '...',
password: '...',
database: '...',
ssl: {
ca: azureCa,
rejectUnauthorized: false
},
insecureAuth: true
});
connection.connect();
const query = 'SELECT id, username, password FROM tb_user WHERE username = ?';
connection.query(query, [ userName ], function(err, results) {
if (err) return callback(err);
if (results.length === 0) return callback(new WrongUsernameOrPasswordError(userName));
const user = results[0];
bcrypt.compare(password, user.password, function(err, isValid) {
if (err || !isValid) return callback(err || new WrongUsernameOrPasswordError(user));
return callback(null, {
user_id: user.id,
username: user.username
});
});
});
}
Error returned:
ER_HANDSHAKE_ERROR: Bad handshake
Do I need to add any configuration or do some action to solve this problem?