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.
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
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.