How does "Require Username" work for custom database connections?

A clear explanation of how authentication works when using a custom database connection would be helpful.

For example, on the Database Connections page, on the Custom Database tab, one is able to write custom code to create authentication functionality with an external database.

The login template has parameters for email and password but nothing for username. It’s unclear to me how this is meant to be implemented when a user has the option to login with a username instead of an email.

Similarly, it’s not clear how this information would be stored based on the Create a new user function template.

Hello, @john6,

For Custom Databases, you actually build your own script to retrieve whatever user information you need from the legacy datasource. Once you do that, you build, within the same script, a user profile according to Auth0’s specification.

In this case, instead of attempting to retrieve the email from the legacy datasource, you should attempt to retrieve the username, which you can then put into the Auth0 profile.

The profile would be they copied over to Auth0. If you have Import Mode on, it would also copy the password over, and next time the user authenticates, it would do it against Auth0 and the profile you created in the first login attempt, rather than contacting the legacy datasource.

Let me know if this helps.

Thanks for the response.

I’ve written my own script already for the Login, Create, and Change Password targets within Auth0.

However it’s unclear to me from the login UI how the email/username would be processed.

See this screenshot for example: here is the way a user would login. There is a single field for “username/email”.

Another example is the Sign Up tab of the same prompt. This prompt has two separate inputs for username and for email.

In the back-end Login script, the template begins with function login(email, password, callback) { . There is a spot for email but not for username. Will Auth0’s form send the input for “username/email” to the email parameter?

Similarly in the Create script, the template begins with function create(user, callback) {. Will the user object here contain both the username and email values from the Sign Up form?

Hi @john6,

You are spot-on for both of them :slight_smile: I was going to draft something more extensive but I think you’ve described it quite well.

1 Like

:joy: well, glad to know my intuition was correct then.

I’ll try an implementation and comment here if I get into any issues.

1 Like

Hmmm I’m still having issues with getting this to work. I made a separate topic because there also seems to be an issue with the Test prompt for the Create function.