I have a pre-registration hook that bans some e-mail domains:
module.exports = function (user, context, cb) {
var response = {};
response.user = user;
const blackList = ["foo", "bar", "baz"];
const emailDomain = user.email.split('@')[1].toLowerCase();
let indexInBlackList = blackList.findIndex(element => emailDomain.includes(element));
if (context.connection.name==='Username-Password-Authentication' && indexInBlackList >= 0) {
cb(new Error("Email domain is not allowed to registration"), response);
}
cb(null, response);
};
If I run this in the runner, it seems to work as expected: if an e-mail address matches, there’s an error response like so:
{
"status": "error",
"data": {
"stack": "Error: Email domain is not allowed to registration\n at module.exports (/data/io/node12/76134834-3f02-459c-aee9-4f00d4f173fb/webtask.js:51:8)\n at /data/sandbox/node12/node_modules/auth0-ext-compilers/lib/compilers/user-registration.js:38:16\n at Object.is_authorized (/data/sandbox/node12/node_modules/auth0-ext-compilers/lib/authorization.js:13:81)\n at userRegistrationHandler (/data/sandbox/node12/node_modules/auth0-ext-compilers/lib/compilers/user-registration.js:17:18)\n at /data/sandbox/node12/node_modules/auth0-ext-compilers/lib/adapter.js:74:14\n at finish (/data/sandbox/node12/node_modules/auth0-ext-compilers/node_modules/wreck/lib/index.js:369:16)\n at wrapped (/data/sandbox/node12/node_modules/auth0-ext-compilers/node_modules/hoek/lib/index.js:879:20)\n at module.exports.internals.Recorder.onReaderFinish (/data/sandbox/node12/node_modules/auth0-ext-compilers/node_modules/wreck/lib/index.js:415:16)\n at Object.onceWrapper (events.js:420:28)\n at module.exports.internals.Recorder.emit (events.js:326:22)",
"message": "Email domain is not allowed to registration"
}
}
(The tenant’s universal login settings say “classic” rather than “new”.)
However, if I actually save this and run it on my website, I instead get a generic “We’re sorry, something went wrong when attempting to sign up.” error, which isn’t very actionable for the user.
I assume there’s something wrong with the JS, but why does it work in the runner?