Pre-registration hook says "something went wrong", but not in the runner

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 ='@')[1].toLowerCase();
  let indexInBlackList = blackList.findIndex(element => emailDomain.includes(element));
  if ('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? :slight_smile:

Hi @skuklau,

Welcome to the Community!

It is possible to return an error like this with the New Universal Login Experience.

This doc contains an example:

Hi Dan,

thanks. It works if I enable the new experience and removing the custom login page.

Of note, the JS editor still thinks “PreUserRegistrationError” doesn’t exist:

[ESLint] 'PreUserRegistrationError' is not defined. (no-undef)

Despite this, the error shows as expected.

1 Like

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