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):
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!