# 401 Unauthorized with SSL custom database

**URL:** <https://community.auth0.com/t/401-unauthorized-with-ssl-custom-database/47271>\
**Category:** Get Help\
**Tags:** mysql, ssl, custom-database\
**Created:** [July 31, 2020, 1:12pm UTC](https://community.auth0.com/t/401-unauthorized-with-ssl-custom-database/47271 "2020-07-31T13:12:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![molashidolo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/molashidolo/32/13482_2.png) [@molashidolo](https://community.auth0.com/u/molashidolo)\
**Post date:** [July 31, 2020, 1:12pm UTC](https://community.auth0.com/t/401-unauthorized-with-ssl-custom-database/47271/1 "2020-07-31T13:12:09Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![James.Morrison](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/james.morrison/32/13507_2.png) [@James.Morrison](https://community.auth0.com/u/James.Morrison)\
**Post date:** [August 24, 2020, 4:05pm UTC](https://community.auth0.com/t/401-unauthorized-with-ssl-custom-database/47271/2 "2020-08-24T16:05:23Z")

</div>

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!

> **[Generate and Analyze HAR Files](https://auth0.com/docs/troubleshoot/troubleshooting-tools/generate-and-analyze-har-files)**
>
> Learn how to troubleshoot with HAR files and steps to generate a HAR file.

---

<div class="post-metadata">

**Author:** ![James.Morrison](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/james.morrison/32/13507_2.png) [@James.Morrison](https://community.auth0.com/u/James.Morrison)\
**Post date:** [September 7, 2020, 8:05pm UTC](https://community.auth0.com/t/401-unauthorized-with-ssl-custom-database/47271/4 "2020-09-07T20:05:29Z")

</div>

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