Auth0 Home Blog Docs

I have an issue with my "get user" script from custom database. "Script generated an unhandled asynchronous exception.”


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…”);

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, {

made this topic public #2

Hey there @cperez, when you get a minute can you take a look at your possibly adjusting your callback function as it may have been the cause of error? Also if you get a chance can you DM me your tenant name so I can take a deeper look at what may be going on here? I have also linked the Get User documentation below for a historical point of reference to add context. Thanks!

MySQL Template

function getByEmail (name, callback) {
  var profile = {
    user_id:     "103547991597142817347",
    nickname:    "johnfoo",
    email:       "",
    name:        "John Foo",
    given_name:  "John",
    family_name: "Foo"

  callback(null, profile);
1 Like

I DM you my tenant name! thanks for replying back


Hi I don’t think that is the correct script because this will give the exact user details what you are giving there like “johnfoo” but not the user details as they are expecting.when am dealing with this problem some auth0 support team told me that there is a issue with the documentation and asked me to try another script which is worked for me. Am sharing this here because it may help someone who are dealing with the same problem


1 Like

Thank you for sharing that @sravya! @cperez do you have some time to give it a shot?


I wanted to follow up @cperez and see how everything is going? Thanks!

closed #10

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