# Domain restriction in combo with Social Connection

**URL:** <https://community.auth0.com/t/domain-restriction-in-combo-with-social-connection/9923>\
**Category:** Get Help\
**Tags:** login\
**Created:** [March 9, 2018, 12:34pm UTC](https://community.auth0.com/t/domain-restriction-in-combo-with-social-connection/9923 "2018-03-09T12:34:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mohamad.bitar](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@mohamad.bitar](https://community.auth0.com/u/mohamad.bitar)\
**Post date:** [March 9, 2018, 12:34pm UTC](https://community.auth0.com/t/domain-restriction-in-combo-with-social-connection/9923/1 "2018-03-09T12:34:21Z")

</div>

_Please fill out the following to the best of your ability. Doing so will help out the troubleshooting process_

- What are you trying to achieve? What is the use case or idea behind it?

In my application, I have sign-in with Google since our company’s email provider is google. Though, I want to restrict the app to the domains ending with @weissmaler.de. I have created a pre-registration hook and/or rule to specify allowed domains. Though, I am still able to log-in with Google using my personal `@gmail.com` email. Is there a way to implement such a logic?

- If this is caused by an SDK please mention the SDK along with the specific version number.

- Is this easily reproducible? If not, please explain.

Yes, as explained in the question

- If this is related to Lock / any SDK please share the SDK as well as lock initialization code or any code that is relevant.

- If this is an issue with an API please mention the endpoint you are trying to hit. Relevant code, and or a network trace, is really helpful when debugging such issues.

- Environment-specific information (Which OS, Language Runtime + Version, Browser etc).

---

<div class="post-metadata">

**Author:** ![kimcodes](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/kimcodes/32/81052_2.png) [@kimcodes](https://community.auth0.com/u/kimcodes)\
**Post date:** [March 15, 2018, 3:05pm UTC](https://community.auth0.com/t/domain-restriction-in-combo-with-social-connection/9923/2 "2018-03-15T15:05:07Z")

</div>

👋 @mohamad.bitar

You say you created a pre-registration hook and/or rule to specify allowed domains, but which one did you try implementing?

You can implement this as a [rule](https://auth0.com/docs/rules/current). We can use the [email domain whitelist](https://auth0.com/rules/simple-domain-whitelist) to accomplish this.

Code example here:

```auto
function (user, context, callback) {
    var whitelist = ['weissmaler.de']; // authorized domains
    var userHasAccess = whitelist.some(
      function (domain) {
        var emailSplit = user.email.split('@');
        return emailSplit[emailSplit.length - 1].toLowerCase() === domain;
      });

    if (!userHasAccess) {
      return callback(new UnauthorizedError('Access denied.'));
    }

    return callback(null, user, context);
}

```

Please let me know if this solves your problem! If not, can you share the code where you specify allowed domains? More than happy to work through it with you.

---

<div class="post-metadata">

**Author:** ![mohamad.bitar](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@mohamad.bitar](https://community.auth0.com/u/mohamad.bitar)\
**Post date:** [March 16, 2018, 8:42am UTC](https://community.auth0.com/t/domain-restriction-in-combo-with-social-connection/9923/3 "2018-03-16T08:42:41Z")

</div>

Thank you for replying, I have this rule already but with no effect. I also tried a pre-registration hook as the following:

```
/**
@param {object} user - The user being created
@param {string} user.tenant - Auth0 tenant name
@param {string} user.username - user name
@param {string} user.password - user's password
@param {string} user.email - email
@param {boolean} user.emailVerified - is e-mail verified?
@param {string} user.phoneNumber - phone number
@param {boolean} user.phoneNumberVerified - is phone number verified?
@param {object} context - Auth0 connection and other context info
@param {string} context.requestLanguage - language of the client agent
@param {object} context.connection - information about the Auth0 connection
@param {object} context.connection.id - connection id
@param {object} context.connection.name - connection name
@param {object} context.connection.tenant - connection tenant
@param {object} context.webtask - webtask context
@param {function} cb - function (error, response)
*/
module.exports = function (user, context, cb) {
  var response = {};
  var domain ='@weissmaler.de';
  
  var okDomain = false;
  
  
  if (user.email.indexOf(domain) > -1) {
    okDomain=domain;
    i=domain.length;
  }

  
  if ((user.emailVerified) || (!user.emailVerified && okDomain)) {
   response.user = user;
   return cb(null, response);  
  } else {
    const error = new Error("E-Mail-Address did not match requirements.");
    error.statusCode = 400;
    return cb(error);
  }
  
};

```

Still, after choosing to login using google, it bypasses those rules/hooks and registers the new user ([user@gmail.com](mailto:user@gmail.com) still goes through). Am I doing something wrong or missing something?

---

<div class="post-metadata">

**Author:** ![kimcodes](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/kimcodes/32/81052_2.png) [@kimcodes](https://community.auth0.com/u/kimcodes)\
**Post date:** [July 17, 2018, 7:32pm UTC](https://community.auth0.com/t/domain-restriction-in-combo-with-social-connection/9923/4 "2018-07-17T19:32:54Z")

</div>

@mohamad.bitar were you able to solve your issue for allowed domains? Please let me know if you still require assistance.

---

<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 26, 2019, 7:25am UTC](https://community.auth0.com/t/domain-restriction-in-combo-with-social-connection/9923/5 "2019-07-26T07:25:34Z")

</div>


