# Calling getUsersByEmail in a post-login trigger?

**URL:** <https://community.auth0.com/t/calling-getusersbyemail-in-a-post-login-trigger/190035>\
**Category:** Get Help\
**Tags:** account-linking, user-management\
**Created:** [August 1, 2025, 4:55pm UTC](https://community.auth0.com/t/calling-getusersbyemail-in-a-post-login-trigger/190035 "2025-08-01T16:55:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Carbon](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/carbon/32/72075_2.png) [@Carbon](https://community.auth0.com/u/Carbon)\
**Post date:** [August 1, 2025, 4:55pm UTC](https://community.auth0.com/t/calling-getusersbyemail-in-a-post-login-trigger/190035/1 "2025-08-01T16:55:23Z")

</div>

We are trying to prevent users from creating duplicate accounts for the same email address (auth0 vs SSO).

It’s possible to prevent an auth0 provider account in the `pre-registration` Trigger by looking up existing users with the same email address using the ManagementClient. The auth0 ManagementClient appears to be available by default here, we didn’t even need to add it as a dependency.

This same approach does not appear to work in the `post-login` Trigger. First off it throws an error if we don’t add auth0 as a dependency. But even if we do, it throws an error saying that `getUsersByEmail` is not available even though the API specs say it should be available. Is it blocked in this Trigger?

The solution we are trying to implement is:

- When a user logs in with SSO for the first time (based on `login_count`)
- Check if an account exists already for the auth0 provider
- If it exists and the account is not `email_verified = true` then reject the login and ask them to login with username and password
- If it exists and the account is `email_verified = true` then go ahead and auto-link the account so they share the same id.

Is this possible?

---

<div class="post-metadata">

**Author:** ![remus.ivan](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/remus.ivan/32/68771_2.png) [@remus.ivan](https://community.auth0.com/u/remus.ivan)\
**Post date:** [August 14, 2025, 3:38pm UTC](https://community.auth0.com/t/calling-getusersbyemail-in-a-post-login-trigger/190035/3 "2025-08-14T15:38:07Z")

</div>

Hi @Carbon,

Welcome to the Auth0 Community and sorry for the late response!  
Moved this post over to the Help Category in order to receive proper assistance.

Your desired implementation is definitely possible. A similar issue was already raised here, so you can check out this [community post](https://community.auth0.com/t/action-for-pre-user-registration/109483/2) which will explain how to achieve this.

In a Post-Login Action you’ll also have to initialize the ManagementClient, such as:

```auto
const management = new ManagementClient({
      domain: event.secrets.domain,
      clientId: event.secrets.clientId,
      clientSecret: event.secrets.clientSecret,
  });

```

and retrieve the response:

> const existingUsers = await api.management.usersByEmail.getByEmail({ email: event.user.email });

You can also check out this pages as well:

- [Using the Management API in Actions](https://community.auth0.com/t/using-the-management-api-in-actions/64947)

- [UsersByEmailManage on github](https://auth0.github.io/node-auth0/classes/management.UsersByEmailManager.html#getByEmail)

Then you should be able to achieve your desired flow by denying access and [Linking User Accounts](https://auth0.com/docs/manage-users/user-accounts/user-account-linking/link-user-accounts).

Thanks,  
Remus

---

<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 28, 2025, 3:38pm UTC](https://community.auth0.com/t/calling-getusersbyemail-in-a-post-login-trigger/190035/4 "2025-08-28T15:38:17Z")

</div>

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