401 Unauthorized with SSL custom database

Hello i am having problems trying my login connection to the DB, my script is the following:

function login(email, password, callback) {
  const mysql = require('mysql');
  const bcrypt = require('bcrypt');
  const key = `-----BEGIN RSA PRIVATE KEY-----
  const ca = `-----BEGIN CERTIFICATE-----
  const cert = `-----BEGIN CERTIFICATE-----

  const connection = mysql.createConnection({
    host: configuration.host,
    user: configuration.user,
    password: configuration.password,
    database: configuration.database,
    ssl: {
      key: key,
      cert: cert,
      ca: ca


  const query = 'SELECT userID, 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));
    const user = results[0];

    bcrypt.compare(password, user.password, function(err, isValid) {
      if (err || !isValid) return callback(err || new WrongUsernameOrPasswordError(email));

      callback(null, {
        user_id: user.id.toString(),
        email: user.email

To start with i am using the .PEM files here because if i store them as setting values i get an error when they are being parsed, this is a workaround, but my problem is that with this config i am getting a 401 Unauthorized when i try my connection, my email and password already exists on the DB, the only thing i have in doubt is if the hashed password i have stored matches the bcrypt converted password but i removed all the bcrypt logic and just tried a WrongUsernameOrPasswordError(email) error and it didn’t show, there is some kind of error with the connection and i just can’t figure it out. Any help is appreciated!