# Problems making SSL MySQL connection with custom database

**URL:** <https://community.auth0.com/t/problems-making-ssl-mysql-connection-with-custom-database/6892>\
**Category:** Get Help\
**Tags:** ssl, custom-database\
**Created:** [June 3, 2017, 2:35am UTC](https://community.auth0.com/t/problems-making-ssl-mysql-connection-with-custom-database/6892 "2017-06-03T02:35:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dwatts](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@dwatts](https://community.auth0.com/u/dwatts)\
**Post date:** [June 3, 2017, 2:35am UTC](https://community.auth0.com/t/problems-making-ssl-mysql-connection-with-custom-database/6892/1 "2017-06-03T02:35:12Z")

</div>

I’m trying to use MySQL SSL with a simple Javascript test application. I’m getting an error when I click the Try button to test my Auth0 custom code:

> Invalid response code from the  
> auth0-sandbox: HTTP 400. Unexpected  
> token ;

I’m at a loss as to what it’s trying to tell me. 🙂 It seems to be related to my use of “require(‘mysql@2.7.0’)” which I found referenced in another blog posting. Without this line of code, I get “ER\_ACCESS\_DENIED\_ERROR: Access denied for user”. I have the MySQL server configured to require SSL on the login. I have verified using mysql at the CLI that I can connect to the database using SSL.

I’m new to Auth0 and I’m using the Javascript Quickstart:  
[https://auth0.com/docs/quickstart/spa/vanillajs/03-calling-an-api](https://auth0.com/docs/quickstart/spa/vanillajs/03-calling-an-api)

I’m using Auth0 v8.7:  
[https://cdn.auth0.com/js/auth0/8.7/auth0.js](https://cdn.auth0.com/js/auth0/8.7/auth0.js)

My custom database login script begins with:

```
require('mysql@2.7.0');
function login(email, password, callback) {
  var connection = mysql({
    host: configuration.DB_HOST,
    user: configuration.DB_USER,
    password: configuration.DB_PASS,
    database: configuration.DB_NAME,
    ssl: {
      ca: configuration.DB_CA,
    }
  });

  connection.connect();

```

---

<div class="post-metadata">

**Author:** ![jmangelo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jmangelo/32/7923_2.png) [@jmangelo](https://community.auth0.com/u/jmangelo)\
**Post date:** [June 5, 2017, 4:29pm UTC](https://community.auth0.com/t/problems-making-ssl-mysql-connection-with-custom-database/6892/2 "2017-06-05T16:29:25Z")

</div>

The customs script you configured **uses invalid syntax** which leads to the error you mentioned.

If you want to require a specific node module to be used within the script you should do something similar to the following:

```
function login(email, password, callback) {
  var mysql = require("mysql@2.7.0");

  var connection = mysql({ /* ... */ });

  // ...
}

```

Notice that the `require` is performed within the custom script main function and the result is assigned to a variable so that it can later be used. You were doing a require outside the main custom script function and also not assigning the output which is invalid.

---

<div class="post-metadata">

**Author:** ![dwatts](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@dwatts](https://community.auth0.com/u/dwatts)\
**Post date:** [June 6, 2017, 3:42am UTC](https://community.auth0.com/t/problems-making-ssl-mysql-connection-with-custom-database/6892/3 "2017-06-06T03:42:26Z")

</div>

Thanks @jmangelo ! I changed my code to be:

var mysql = require(‘mysql@2.7.0’);  
var connection = mysql.createConnection({  
ssl: {  
ca: configuration.DB\_CA,  
rejectUnauthorized: false  
} … });

And now it works. I had to add the rejectUnauthorized because my server is using a self signed certificate for mysqld.

---

<div class="post-metadata">

**Author:** ![dwatts](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@dwatts](https://community.auth0.com/u/dwatts)\
**Post date:** [June 6, 2017, 3:42am UTC](https://community.auth0.com/t/problems-making-ssl-mysql-connection-with-custom-database/6892/4 "2017-06-06T03:42:26Z")

</div>

Thanks @jmangelo ! I changed my code to be:

var mysql = require(‘mysql@2.7.0’);  
var connection = mysql.createConnection({  
ssl: {  
ca: configuration.DB\_CA,  
rejectUnauthorized: false  
} … });

And now it works. I had to add the rejectUnauthorized because my server is using a self signed certificate for mysqld.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [March 2, 2018, 5:54am UTC](https://community.auth0.com/t/problems-making-ssl-mysql-connection-with-custom-database/6892/5 "2018-03-02T05:54:21Z")

</div>


