Auth0 Home Blog Docs

Custom MySql Connection Is not working Showing 401 - Unauthorized Error

lock
auth0
mysql

#1

Hi All,

I am trying to connect own mysql server using CUSTOM MySql Database.
I have added following script in login Database Action Scripts.

 function login(email, password, callback) {
  var connectionConfiguration = {
    host: '35.154.162.95',
    user: 'test',
    password: 'LUws4tVNP0s9m2mJ',
    database: 'test'
  };
  var connection = mysql(connectionConfiguration);
  connection.connect(function(err) {
    if (err) {
      console.log(connectionConfiguration);
      console.error('error connecting: ' + err.stack);
      return;
    }
    console.log('connected as id ' + connection.threadId);
});
  var query = "SELECT * 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));
    var user = results[0];

    bcrypt.compare(password, user.password, function (err, isValid) {
      if (err) {
        callback(err);
      } else if (!isValid) {
        callback(new WrongUsernameOrPasswordError(email));
      } else {
        callback(null, {
          id: user.id.toString(),
          nickname: user.nickname,
          email: user.email
        });
      }
    });

  });
}

But it is showing the error of 401 - Unauthorized .

Please help me out.


#2

After debugging the issue, i found this.


#3

But still getting 401 - Unauthorized .