Auth0 Home Blog Docs

"error": "Script generated an unhandled asynchronous exception."

custom-database
#1

I’m trying to get the custom database connection to work. I was told to try the “Get user” method first to test the database connection. I’ve added the code below but I get an error “Script generated an unhandled asynchronous exception.”

function getByEmail(email, callback) {

console.log(“Executing Get User script…”);
const mysql = require(‘mysql@2.16.0’);

const connection = mysql.createConnection({
host: configuration.DB_HOST,
user: configuration.DB_USER,
password: configuration.DB_PASSWORD,
database: configuration.DB_NAME,
ssl: {
rejectUnauthorized: false,
cert: new Buffer(configuration.DB_CLIENT_CERT, ‘base64’)
}
});

console.log(“Preparing connection to DB…”);

connection.connect();
console.log(“Connected to DB: OK!”);
const query = ‘SELECT id, email FROM users WHERE email = ?’;

console.log("Query DB for email: " + email);
connection.query(query, [ email ], function(err, results) {
console.log("Error???: " + err);
if (err || results.length === 0) return callback(err || null);
console.log(“Query executed OK!”);
console.log("Users found: " + results.length);
if (results.length === 0) return callback();
const user = results[0];

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

});
}

#2

Hey there @cperez, I was hoping to find out more about the “Script generated an unhandled asynchronous exception” error you are experiencing. Also when you get a chance can you DM me your tenant name? Thanks in advance.

#4

I wanted to touch base on this “Script generated an unhandled asynchronous exception” error and was hoping you could share more details when you get a chance. Please let me know if you have any questions, thanks!

closed #5

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