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);
});
});
});
});
}