# Unique email in single tenant using actions

**URL:** <https://community.auth0.com/t/unique-email-in-single-tenant-using-actions/97320>\
**Category:** Get Help\
**Tags:** custom-database-connections, connections\
**Created:** [January 2, 2023, 2:25pm UTC](https://community.auth0.com/t/unique-email-in-single-tenant-using-actions/97320 "2023-01-02T14:25:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![miroslav.bartl](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/miroslav.bartl/32/39185_2.png) [@miroslav.bartl](https://community.auth0.com/u/miroslav.bartl)\
**Post date:** [January 2, 2023, 2:25pm UTC](https://community.auth0.com/t/unique-email-in-single-tenant-using-actions/97320/1 "2023-01-02T14:25:39Z")

</div>

How do I outright block the user (e.g. show an error message) if he’s trying to sign up using one social connection (e.g. Facebook) when he’s already registered through another social connection (e.g. Google) or single database using actions?

In my use case I have single user database, Facebook and Google only.

- I don’t want to use account linking extension because that extension still allows the user to skip the linking.
- I don’t want to use rules/hooks because Auth0 is telling me these are obsolete.
- I need to verify email uniqueness just in a single tenant. I’m saying this because there is other topic in the forums asking for uniqueness across multiple tenants.

---

<div class="post-metadata">

**Author:** ![SaqibHussain](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/saqibhussain/32/42924_2.png) [@SaqibHussain](https://community.auth0.com/u/SaqibHussain)\
**Post date:** [January 26, 2023, 4:03pm UTC](https://community.auth0.com/t/unique-email-in-single-tenant-using-actions/97320/3 "2023-01-26T16:03:49Z")

</div>

Hi @miroslav.bartl

Welcome back to the Auth0 Community.

You should be able to achieve this with a Post Login Action, something like the below you can chop and change to meet your needs.

```auto
exports.onExecutePostLogin = async (event, api) => {
  const ManagementClient = require('auth0').ManagementClient;
  const management = new ManagementClient({
    domain: event.secrets.domain,
    clientId: event.secrets.clientId,
    clientSecret: event.secrets.clientSecret,
  });

  const params = {
    search_engine: 'v3',
    q: `email:"${event.user.email}"`
  };

  try {
    const users = await management.getUsers(params);
    if (users.length > 0) {
      management.users.delete({ id: event.user.user_id });
      api.access.deny('This email address already exists');
    }
  } catch (e) {
    console.log(e)
    // Handle error
  }
  
};

```

This guide will introduce you to Actions if you’re not familiar with it [https://auth0.com/docs/customize/actions/write-your-first-action](https://auth0.com/docs/customize/actions/write-your-first-action)

Please let me know if you need anything further.

Warm regards.

---

<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:** [February 9, 2023, 4:04pm UTC](https://community.auth0.com/t/unique-email-in-single-tenant-using-actions/97320/4 "2023-02-09T16:04:07Z")

</div>

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