Username does not work for custom mongodb connection

Hi @raalrwai ,

The sample template is assuming you are using emails only, not usernames.

When you enable “Requires Username”, you will need to add additional logic to your Custom DB scripts to be able to handle the email parameter being passed as either an email or a username, and be able to find the user correctly with either. In both cases, it should return the same profile, including the username in said profile so it can be stored in Auth0 (for import mode).

This is mentioned in the docs:

The email address for the user as the user identifying credential. If Requires Username is enabled for your connection, the Get User script may run multiple times for some transactions (ex. Creating a user, or requesting a password reset link). In these cases the value of the parameter will sometimes be a username instead of an email. Your code should be able to handle either value and always return the same profile for a given user regardless of whether they were looked up by email or username.

You may find using an $or operator to carry out the search for the “email” parameter in email or username useful if either can be used in your use case: node.js - Mongodb findOne with or - Stack Overflow