Login Flow Action Error with not created email

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.

    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.

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 emaillink

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

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