# Login Flow Action Error with not created email

**URL:** <https://community.auth0.com/t/login-flow-action-error-with-not-created-email/106863>\
**Category:** Get Help\
**Tags:** new-universal-login-experience, login-experience\
**Created:** [May 13, 2023, 6:20pm UTC](https://community.auth0.com/t/login-flow-action-error-with-not-created-email/106863 "2023-05-13T18:20:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hiekki4](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@hiekki4](https://community.auth0.com/u/hiekki4)\
**Post date:** [May 13, 2023, 6:20pm UTC](https://community.auth0.com/t/login-flow-action-error-with-not-created-email/106863/1 "2023-05-13T18:20:30Z")

</div>

Hello, i created a action so users can’t login/register with the same account in database or social, but when i try to login the system says that the account already exits, but i don’t.

```auto
    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('It looks like there is already an account associated with this email. Login or reset your password if you forgot it.');
        }
    } catch (e) {
        console.log(e)
        api.access.deny('Something went wrong. Please try again later.');
    }

```

The idea was to like when a user creates an account with the connection database, and if he tries to login with social connection and the email is the same it deletes the account and return error.

---

<div class="post-metadata">

**Author:** ![dawid.matuszczyk](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dawid.matuszczyk/32/74550_2.png) [@dawid.matuszczyk](https://community.auth0.com/u/dawid.matuszczyk)\
**Post date:** [July 31, 2023, 2:26pm UTC](https://community.auth0.com/t/login-flow-action-error-with-not-created-email/106863/3 "2023-07-31T14:26:01Z")

</div>

Hi @hiekki4

Welcome back to the Auth0 Community!

I appreciate your patience. I’ve checked the query you provided, and the first thing I noticed is that with the current approach, you will constantly hit Management API, which can easily lead to hitting the upper request limit. I suggest moving this code snipper behind conditional statements like first user login/ after password reset, anything that will work for you.

The 2nd thing is that instead of searching Users with params, you can use `search users by email` → [link](https://auth0.com/docs/api/management/v2/users-by-email/get-users-by-email)

Last but not least why, your code snippet can not work due to the Pre-User Registration Action nature. It will only trigger runs when a user attempts to register through a Database or Passwordless connection, not a social connection.

As a last word, account linking is a feature we are still developing for the Actions, as Rules and Hooks have been deprecated. I will keep you informed about the progress.

Thanks, and have a great day!

Dawid

---

<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 14, 2023, 2:26pm UTC](https://community.auth0.com/t/login-flow-action-error-with-not-created-email/106863/4 "2023-08-14T14:26:33Z")

</div>

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