# Restrict certain emails to only Social Login

**URL:** <https://community.auth0.com/t/restrict-certain-emails-to-only-social-login/90726>\
**Category:** Get Help\
**Tags:** login\
**Created:** [September 15, 2022, 6:32pm UTC](https://community.auth0.com/t/restrict-certain-emails-to-only-social-login/90726 "2022-09-15T18:32:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pipeabellos](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/pipeabellos/32/39983_2.png) [@pipeabellos](https://community.auth0.com/u/pipeabellos)\
**Post date:** [September 15, 2022, 6:32pm UTC](https://community.auth0.com/t/restrict-certain-emails-to-only-social-login/90726/1 "2022-09-15T18:32:51Z")

</div>

Hello,

I’m trying to restrict certain domains to only signup/login using social login. For example, if a user with an email “@test123.com” tries to signup/login using the email, and password boxes, the access should be denied since this user should only be able to login using the Social Login option in my App.

---

<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:** [September 15, 2022, 8:13pm UTC](https://community.auth0.com/t/restrict-certain-emails-to-only-social-login/90726/3 "2022-09-15T20:13:10Z")

</div>

Hey there @pipeabellos welcome to the community!

> [@pipeabellos](#):
>
> I’m trying to restrict certain domains to only signup/login using social login.

You should be able to implement this with a [pre user registration](https://auth0.com/docs/customize/actions/flows-and-triggers/pre-user-registration-flow) action wherein you use `api.access.deny` to deny the registration. You’ll have the user context as well details about the connection used in the [event](https://auth0.com/docs/customize/actions/flows-and-triggers/pre-user-registration-flow/event-object) object. There’s an example of denying a registration (different criteria) in the blog post below:

> **[Limit User Registration to Specific Dates with Auth0 Actions](https://auth0.com/blog/limit-user-registration-to-specific-dates-with-auth0-actions/)**
>
> With Auth0’s Actions, it’s easy to ensure that users can sign up for an account only between a specific start date and end date.

Alternatively, you could just forego having a database connection altogether:

> **[Actions Triggers: pre-user-registration - Event Object](https://auth0.com/docs/customize/actions/flows-and-triggers/pre-user-registration-flow/event-object)**
>
> Learn about the pre-user-registration Action trigger's event object, which provides contextual information about the request to register a new user.

Hope this helps!

---

<div class="post-metadata">

**Author:** ![pipeabellos](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/pipeabellos/32/39983_2.png) [@pipeabellos](https://community.auth0.com/u/pipeabellos)\
**Post date:** [September 15, 2022, 8:17pm UTC](https://community.auth0.com/t/restrict-certain-emails-to-only-social-login/90726/4 "2022-09-15T20:17:39Z")

</div>

Thank you @ty.frith ! I’m not that technical so I can’t write the code by myself. Do you have any examples on how this action must be written?

---

<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:** [September 15, 2022, 9:09pm UTC](https://community.auth0.com/t/restrict-certain-emails-to-only-social-login/90726/5 "2022-09-15T21:09:17Z")

</div>

No problem, happy to help!

> [@pipeabellos](#):
>
> Do you have any examples on how this action must be written?

It really depends on your specific use case - It may be easier to just forego having a database (username/password) connection altogether. This way only the Social providers will be displayed to the user. However, if you do have a db connection for other users your action might look like:

```auto
exports.onExecutePreUserRegistration = async (event, api) => {
  //using this logic for a specific app/client_id
  if (event.client.client_id === `YOUR_CLIENT_ID`) {
    //check if the user is attempting to register with a specific domain
      if (event.user.email.includes("@exampledomain")) {
      const LOG_MESSAGE = "Registration denied"
      const USER_MESSAGE = "Registration denied - Please login using Google"
      api.access.deny(LOG_MESSAGE, USER_MESSAGE)
    }
  }
}

```

This would result in the following:

 ![Screen Shot 2022-09-15 at 2.06.00 PM](https://global.discourse-cdn.com/auth0/original/3X/b/e/bed4b9339f51b84e29a287839d746943fd69f3e7.png)

This is just a quick example I’ve thrown together 🙂 You’ll definitely want to run this by someone on your end with technical experience, but hope this helps!

---

<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:** [September 29, 2022, 9:09pm UTC](https://community.auth0.com/t/restrict-certain-emails-to-only-social-login/90726/6 "2022-09-29T21:09:22Z")

</div>

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