# Need sample code for Email domain whitelist to use in actions

**URL:** <https://community.auth0.com/t/need-sample-code-for-email-domain-whitelist-to-use-in-actions/112603>\
**Category:** Get Help\
**Tags:** email-verification, user-management\
**Created:** [August 1, 2023, 5:54pm UTC](https://community.auth0.com/t/need-sample-code-for-email-domain-whitelist-to-use-in-actions/112603 "2023-08-01T17:54:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![santhosh.nethaji](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@santhosh.nethaji](https://community.auth0.com/u/santhosh.nethaji)\
**Post date:** [August 1, 2023, 5:54pm UTC](https://community.auth0.com/t/need-sample-code-for-email-domain-whitelist-to-use-in-actions/112603/1 "2023-08-01T17:54:20Z")

</div>

We are working on to migrate from Rules to action. We need sample code of Email domain verification to use in action.

Currently, we are using below code in Rules.

```auto
function emailDomainWhitelist(user, context, callback) {
  // Access should only be granted to verified users.
  if (!user.email || !user.email_verified) {
    return callback(new UnauthorizedError('Access denied.'));
  }

  const whitelist = ['gmail.com']; //authorized domains
  const userHasAccess = whitelist.some(function (domain) {
    const emailSplit = user.email.split('@');
    return emailSplit[emailSplit.length - 1].toLowerCase() === domain;
  });

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

  return callback(null, user, context);
}

```

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [August 2, 2023, 3:00pm UTC](https://community.auth0.com/t/need-sample-code-for-email-domain-whitelist-to-use-in-actions/112603/3 "2023-08-02T15:00:36Z")

</div>

Hi @santhosh.nethaji,

Welcome to the Auth0 Community!

Here is the script converted to an Action for your convenience:

```auto
exports.onExecutePostLogin = async (event, api) => {
 if(!user.event.email || !user.event.email_verified){
   api.access.deny('invalid_request', "Access denied.");
 }

 const email = event.user.email.split('@')[1]
 const whitelist = ["gmail.com"]
  if (whitelist.includes(email)) {
    api.access.deny('invalid_request', "Access denied");
  }
};

```

I have attached some useful resources around migrating from Rules to Actions:

- [Migrate from Rules to Actions](https://auth0.com/docs/customize/actions/migrate/migrate-from-rules-to-actions)
- [Actions Limitations](https://auth0.com/docs/customize/actions/limitations)
- [Post Login Action](https://auth0.com/docs/customize/actions/flows-and-triggers/login-flow)

I hope this helps!

Thanks,  
Rueben

---

<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:** [August 16, 2023, 3:01pm UTC](https://community.auth0.com/t/need-sample-code-for-email-domain-whitelist-to-use-in-actions/112603/4 "2023-08-16T15:01:15Z")

</div>

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