Auth0 Real-time Webtask Logs Extension not working and user not getting stored in database

I am using the Auth0 Real-time Webtask Logs Extension to debug the create action script of my custom database. I have placed a few console log statements in the script, but nothing is being outputted in the Real-time Webtask Logs. I have already installed and configured the extension in my Auth0 dashboard, and I have selected the correct tenant in the Real-time Webtask Logs Extension console. I have also checked the logs in the Auth0 dashboard to make sure that the script is being executed and that there are no errors. However, the output from the console log statements is still not being displayed in the Real-time Webtask Logs Extension console.

The other problem is that the user is not getting stored in the database after registration. The script seems to be executing correctly as I am able to receive the authResult that is returned by the callback of auth0.WebAuth.signup() method, but the user is not being added to the database. I am not sure if these two issues are related or if there is a separate issue with the database connection or the insert query.

Here’s what my signup code looks like:

const auth0 = new auth0.WebAuth({
  clientID: 'MY_CLIENT_ID',
  domain: 'MY_AUTH0_DOMAIN'
});

auth0.WebAuth.signup({
  connection: 'Username-Password-Authentication',
  email: 'user@example.com',
  password: 'password',
  userMetadata: { // this will be stored in user_metadata
    firstName: 'John',
    lastName: 'Doe'
  }
}, function(err, result) {
  if (err) {
    console.error(err);
  } else {
    console.log(result);
  }
});

Here is what my create action script looks like:

function create(user, callback) {
  const mysql = require('mysql');
  const bcrypt = require('bcrypt');

  const connection = mysql.createConnection({
    host: 'host',
    user: 'user',
    password: 'pwd',
    database: 'database',
    port: 8000,
  });
  
  console.log("test");

  connection.connect();

  const query = 'INSERT INTO users SET ?';

  bcrypt.hash(user.password, 10, function(err, hash) {
    const insert = {
      fname: user.firstName,
      lname: user.lastName,
      email: user.email,
      password: hash,  
    };

    connection.query(query, insert, function (err, results) {
      console.log("saving");
      if (err) return callback(err);
      if (results.length === 0) return callback();
      console.log("success");
      callback(null);
    });
  });
}

FYI, when I test the script using Auth0’s Save and Try feature, the user gets stored in the database. Also, the login script works without any issues.

How can I fix these issues and ensure that the Real-time Webtask Logs Extension works and the user gets stored in the database after registration?

1 Like