User Import in custom database not working as expected

I activated the user import for a database in auth0 connected to a custom database.
I wrote the login and getUser scripts, it works great without import but with the import it does not work.

For example, if I login to my app with the user “John”, he is correctly migrated to Auth0 with correct data.
But if I logout and I login again with the same user I have a problem. The login script is ran again while he does not according to the schema on this page Configure Automatic Migration from Your Database

And in the logs I have this issue:

The user 99999 is already imported. Verify if the user has changed the email. New email: - Old email:

I was only able to reproduce this situation when I made my login script return multiple users with the same user identifier or same email. Ensure that the script always consistently returns the same user identifier (if you’re still testing and making changes to the script and user identifier generation it may be best to remove and recreate the connection).

Also have in mind that even though your custom database could accept same email for different users the Auth0 custom database connection expects unique user emails.

Finally, if none of the above proves to be the issue can you update your questions with the minimal amount of steps to reproduce this and with more information about the user properties that triggers the problem.