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-----
...
-----END RSA PRIVATE KEY-----`;
  
  const ca = `-----BEGIN CERTIFICATE-----
...
-----END CERTIFICATE-----`;
  
  const cert = `-----BEGIN CERTIFICATE-----
...
-----END CERTIFICATE-----`;

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

  connection.connect();

  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!

Thanks!

Hi there @molashidolo, welcome to the Auth0 Community, and I apologize for the delay!

To take a deeper look at this do you mind sharing your tenant name and HAR file capture of the failed auth through a direct message with me when you get a chance? This will allow us to take a deeper look at whats going on. Thanks in advance!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.