# Callback is not a function error when trying to conect custom DB

**URL:** <https://community.auth0.com/t/callback-is-not-a-function-error-when-trying-to-conect-custom-db/182113>\
**Category:** Get Help\
**Tags:** regular-database-connections, connections\
**Created:** [February 13, 2025, 4:29pm UTC](https://community.auth0.com/t/callback-is-not-a-function-error-when-trying-to-conect-custom-db/182113 "2025-02-13T16:29:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![lorenzoc](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/lorenzoc/32/72645_2.png) [@lorenzoc](https://community.auth0.com/u/lorenzoc)\
**Post date:** [February 13, 2025, 4:29pm UTC](https://community.auth0.com/t/callback-is-not-a-function-error-when-trying-to-conect-custom-db/182113/1 "2025-02-13T16:29:34Z")

</div>

Hi Everyone, I’m quite new to Aut0 and I’m trying to integrate it into my web app.

I’m trying to set up a connection to my app database using the following code I found on this community (BTW thanks to the author):

````auto
function login(email, password, context, callback) {
  const mysql = require('mysql');
  const bcrypt = require('bcrypt');

  const connection = mysql.createConnection({
    host: '1.1.1.1',
    user: 'user',
    password: 'password',
    database: 'database'
  });

  connection.connect();
  
  const query = 'SELECT user_id, username, email, password FROM user 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];

    const hashPass = /^\$2y\$/.test(user.password) ? '$2a$' + user.password.slice(4) : user.password;
    bcrypt.compare(password, hashPass, function(err, isValid) {
      if (err || !isValid) {
        console.log("bcrypt.compare failed");
        return callback(err || new WrongUsernameOrPasswordError(email));
      }

	  
	    callback(null, {
        user_id: user.user_id.toString(),
        username: user.username,
        email: user.email
      });
    });
  });
}```

````

The problem is that when I test the custom database connection I get the “Callback is not a function” error.

Doesn anyone know what can be the reason?

Thanks a lot!

---

<div class="post-metadata">

**Author:** ![lorenzoc](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/lorenzoc/32/72645_2.png) [@lorenzoc](https://community.auth0.com/u/lorenzoc)\
**Post date:** [February 13, 2025, 6:06pm UTC](https://community.auth0.com/t/callback-is-not-a-function-error-when-trying-to-conect-custom-db/182113/3 "2025-02-13T18:06:06Z")

</div>

Seems it was jsut a syntax issue. In case someone may need it the correct code is the following:

````auto
function login(email, password, callback) {
  const mysql = require('mysql');
  const bcrypt = require('bcrypt');
  
  const connection = mysql.createConnection({
    host: '1.1.1.1',
    user: 'user',
    password: 'password',
    database: 'database'
  });
  
  connection.connect();
  
  const query = 'SELECT user_id, username, email, password FROM user 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];
    
	const hashPass = /^\$2y\$/.test(user.password) ? '$2a$' + user.password.slice(4) : user.password;
	
     bcrypt.compare(password, hashPass, function(err, isValid) {
      if (err || !isValid) {
        console.log("bcrypt.compare failed");
        return callback(err || new WrongUsernameOrPasswordError(email));
      }
	 callback(null, {
        user_id: user.user_id.toString(),
        username: user.username,
        email: user.email
      });
    });
  });
}```
````

---

<div class="post-metadata">

**Author:** ![gerald.czifra](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/gerald.czifra/32/75301_2.png) [@gerald.czifra](https://community.auth0.com/u/gerald.czifra)\
**Post date:** [February 14, 2025, 8:34pm UTC](https://community.auth0.com/t/callback-is-not-a-function-error-when-trying-to-conect-custom-db/182113/4 "2025-02-14T20:34:25Z")

</div>

Hi @lorenzoc

Thank you for sharing the solution with the Community, your input is surely going to help others facing this issue!

Have a great one!  
Gerald

---

<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:** [February 28, 2025, 8:35pm UTC](https://community.auth0.com/t/callback-is-not-a-function-error-when-trying-to-conect-custom-db/182113/5 "2025-02-28T20:35:23Z")

</div>

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