try-create script not working

I’m trying to test my create script for my custom db, but it keeps returning
[WrongUsernameOrPasswordError] wrongusernameorpassword - undefined
However, this error is no where in my script. I’ve put console.log statements all over my script but none of them are being logged, not even ones at the beginning of the script. There are no other errors or messages in the console or in the live logs. I have no idea how to proceed. Here is my code:

function create (user, callback) {
  console.log("hello");
  // This script should create a user entry in your existing database. It will
  // be executed when a user attempts to sign up, or when a user is created
  // through the Auth0 dashboard or API.
  // When this script has finished executing, the Login script will be
  // executed immediately afterwards, to verify that the user was created
  // successfully.
  //
  // The user object will always contain the following properties:
  // * email: the user's email
  // * password: the password entered by the user, in plain text
  // * tenant: the name of this Auth0 account
  // * client_id: the client ID of the application where the user signed up, or
  //              API key if created through the API or Auth0 dashboard
  // * connection: the name of this database connection
  //
  // There are three ways this script can finish:
  // 1. A user was successfully created
  //     callback(null);
  // 2. This user already exists in your database
  //     callback(new ValidationError("user_exists", "my error message"));
  // 3. Something went wrong while trying to reach your database
  //     callback(new Error("my error message"));

  console.log("here");
  //return callback(new Error("WTF"));
  var conString = configuration.DATABASE_URL + "?ssl=true";
  postgres(conString, function (err0, client, done) {
    console.log("here2");
    if (err0) {
      console.log('could not connect to postgres db', err0);
      return callback(new Error("Something went wrong!"));
    }

    var query = 'SELECT * FROM "users" WHERE "email" ILIKE $1';
    var insert = "INSERT INTO \"users\" VALUES(DEFAULT, '', $1, $2, '', 1, null, null, false, null, false, null, true, now(), now())";

    client.query(query, [email], function (err1, result) {
      if (err1) {
        done();
        console.log('error executing query', err1);
        return callback(err);
      }

      if (result.rows.length > 0) {
        done();
        return callback(new ValidationError("user_exists", "Email already exists."));
      }
      
      bcrypt.hash(user.password, 11, function (err2, hash) {
        if (err2) {
          done();
          console.log('error encrypting password', err2);
          return callback(new Error("Something went wrong!"));
        }

        client.query(insert, [user.email, hash], function (err3, result) {
          done();
          if (err3) {
            console.log('error executing query', err3);
            return callback(new Error("Something went wrong!"));
          }
          callback(null);
        });
      });
    });
  });
}

I could not reproduce this with a custom database of my own, but my test database scripts don’t reflect a more real scenario so I might be missing something. I would try the following in order to see if more information surfaces that could allow to identify the cause of this:

  • do a hard reload of the Dashboard, ideally in a new browser session (this one is the typical have you tried turning it off and on again).
  • add a console.log that uniquely identifies each script name as the first operation of every custom database script you have.
  • keep the real-time logs extension open.

After having done the above, try the TRY functionality one more time and see if anything new surfaces. If not, I would create a new custom database connection and do the TRY things with the default scripts just for a quick sanity and then would start replicating the scripts one by one in the new custom database and trying one at a time.

Turns out I was returning that error from the getUserByEmail function since I copied over parts of the login function. I guess the create user script calls the get user script before hand to verify that the user doesn’t exist. It doesn’t mention this anywhere in the documentation I could find.

Now I’m dealing with the Change Password script not being called. The web task doesn’t even fire. Getting this error: {"name":"BadRequestError","code":"invalid_parameter","description":"connection is disabled (client_id: fOTkqSXnY-h66EKqNSwaEExXRyg-n18Z - connection: Custom-Database-Connection)","statusCode":400}