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

**URL:** <https://community.auth0.com/t/pre-registration-hook-says-something-went-wrong-but-not-in-the-runner/63491>\
**Category:** Get Help\
**Tags:** pre-user-registratio\
**Created:** [May 28, 2021, 8:31am UTC](https://community.auth0.com/t/pre-registration-hook-says-something-went-wrong-but-not-in-the-runner/63491 "2021-05-28T08:31:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![skuklau](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/skuklau/32/16125_2.png) [@skuklau](https://community.auth0.com/u/skuklau)\
**Post date:** [May 28, 2021, 8:31am UTC](https://community.auth0.com/t/pre-registration-hook-says-something-went-wrong-but-not-in-the-runner/63491/1 "2021-05-28T08:31:12Z")

</div>

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? 🙂

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [May 28, 2021, 5:08pm UTC](https://community.auth0.com/t/pre-registration-hook-says-something-went-wrong-but-not-in-the-runner/63491/3 "2021-05-28T17:08:12Z")

</div>

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:

> **[Pre-User Registration](https://auth0.com/docs/customize/hooks/extensibility-points/pre-user-registration)**
>
> Learn how Hooks can be used with the Pre-User Registration extensibility point, which is available for database connections and passwordless connections.

---

<div class="post-metadata">

**Author:** ![skuklau](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/skuklau/32/16125_2.png) [@skuklau](https://community.auth0.com/u/skuklau)\
**Post date:** [June 7, 2021, 10:36am UTC](https://community.auth0.com/t/pre-registration-hook-says-something-went-wrong-but-not-in-the-runner/63491/4 "2021-06-07T10:36:26Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [June 22, 2021, 10:36am UTC](https://community.auth0.com/t/pre-registration-hook-says-something-went-wrong-but-not-in-the-runner/63491/5 "2021-06-22T10:36:47Z")

</div>

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