# Can I prevent user from receiving a e-mail code in a rule?

**URL:** <https://community.auth0.com/t/can-i-prevent-user-from-receiving-a-e-mail-code-in-a-rule/45607>\
**Category:** Get Help\
**Tags:** passwordless, auth0\
**Created:** [July 1, 2020, 1:10pm UTC](https://community.auth0.com/t/can-i-prevent-user-from-receiving-a-e-mail-code-in-a-rule/45607 "2020-07-01T13:10:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexab](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/alexab/32/13403_2.png) [@alexab](https://community.auth0.com/u/alexab)\
**Post date:** [July 1, 2020, 1:10pm UTC](https://community.auth0.com/t/can-i-prevent-user-from-receiving-a-e-mail-code-in-a-rule/45607/1 "2020-07-01T13:10:04Z")

</div>

I am using passwordless email, with sign-up enabled.

Is it possible, for example using rules, to prevent certain e-mails/domains from receiving a one-time code?

Currently, everyone who visits the sign-up can provide their e-mail, then a one-time code, and first after this can I validate the user with rules 🤷🏽‍♂️

Motivation:  
Preventing sign-up for certain domains.

---

<div class="post-metadata">

**Author:** ![andy.carter](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/andy.carter/32/27949_2.png) [@andy.carter](https://community.auth0.com/u/andy.carter)\
**Post date:** [July 1, 2020, 2:35pm UTC](https://community.auth0.com/t/can-i-prevent-user-from-receiving-a-e-mail-code-in-a-rule/45607/2 "2020-07-01T14:35:45Z")

</div>

Hi @alexab,

You can prevent passwordless signups for particular domains by using the Pre-User Registration Hook:

[Pre-User Registration](https://auth0.com/docs/hooks/extensibility-points/pre-user-registration)

As an example:

```
module.exports = function (user, context, cb) {
  var response = {};

  response.user = user;

    const pos = user.email.search('@'); // get position of domain
    var domainName = '';
    if (pos > 0) {
       domainName = user.email.slice(pos); // get domain name
    }

  if (domainName === "@disalloweddomain.com" ) {
    cb('Invalid Signup.', response);
  }

  cb(null, response);
};

```

---

<div class="post-metadata">

**Author:** ![alexab](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/alexab/32/13403_2.png) [@alexab](https://community.auth0.com/u/alexab)\
**Post date:** [July 2, 2020, 9:06am UTC](https://community.auth0.com/t/can-i-prevent-user-from-receiving-a-e-mail-code-in-a-rule/45607/3 "2020-07-02T09:06:47Z")

</div>

Hi @andy.carter - that’s amazing. I had the impression that the pre-user-registration hook was not enabled for passwordless, but no 🚀

I will implement this soon, and share any feedback here 🙌🏾

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [July 2, 2020, 9:35am UTC](https://community.auth0.com/t/can-i-prevent-user-from-receiving-a-e-mail-code-in-a-rule/45607/4 "2020-07-02T09:35:40Z")

</div>

Sure! Let us know once you have a chance to test it!

---

<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:** [July 17, 2020, 9:43am UTC](https://community.auth0.com/t/can-i-prevent-user-from-receiving-a-e-mail-code-in-a-rule/45607/5 "2020-07-17T09:43:32Z")

</div>

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