# How to allow specific emails to login with auth0?

**URL:** <https://community.auth0.com/t/how-to-allow-specific-emails-to-login-with-auth0/96912>\
**Category:** Get Help\
**Tags:** passwordless-email-connection, connections\
**Created:** [December 21, 2022, 4:12pm UTC](https://community.auth0.com/t/how-to-allow-specific-emails-to-login-with-auth0/96912 "2022-12-21T16:12:47Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [August 19, 2024, 6:16pm UTC](https://community.auth0.com/t/how-to-allow-specific-emails-to-login-with-auth0/96912/8 "2024-08-19T18:16:16Z")

</div>

Re-visiting this as we comb through our backlog and hope this helps someone in the future 🔮

> [@maury](#):
>
> My bad, sry! 😣. I have an API in .NET and what I would like to do is protect the endpoints so that way specific people can fetch it. In the other hand (here its where it gets cloudly to me) I would like my front-app (here comes auth0, I think?) to have some auth(login option) when you enter it and the only access to pass through it is with a specific email (what I don’t really know is if I need to send some JWT through my back or not)

There are a couple of ways you can go about this - You could simply create an Action to “allow list” specific emails:

```auto
exports.onExecutePostLogin = async (event, api) => {
  // Define your allowlist of emails
  const allowlist = [
    'alloweduser1@example.com',
    'alloweduser2@example.com',
    'alloweduser3@example.com'
  ];

  // Check if the user's email is in the allowlist
  if (!allowlist.includes(event.user.email)) {
    // If the email is not in the allowlist, deny access
    api.access.deny('Access denied: Your email is not in the allowlist.');
  }
};

```

The 2nd and more scaleable approach is to implement [Role Based Access Control](https://auth0.com/docs/manage-users/access-control/rbac) - At a high level this includes assigning roles (and subsequently API permissions) to users. In your registered API settings, you will want to [enable RBAC](https://auth0.com/docs/get-started/apis/enable-role-based-access-control-for-apis) and most likely the option to include permissions in access tokens. When a user logs in they will receive an access token, and if permissions are included in the token these are what your API, after verifying the access token, will use to make authorization decisions. Alternatively or in addition to permissions, you can add roles to your user’s access tokens as well using a Post Login Action:

```auto
exports.onExecutePostLogin = async (event, api) => {
  // Get the user's roles from the event object
  const roles = event.authorization.roles;

  // Add the roles to the access token as a custom claim
  api.accessToken.setCustomClaim('https://your-domain.com/roles', roles);
};

```

---

_[View the full topic](https://community.auth0.com/t/how-to-allow-specific-emails-to-login-with-auth0/96912)._
