Unable to use a username in a database connection if the first is email only

We were using Auth0 lock successfully for a long time using email and password (no username). We are now in the process of converting an old system that has usernames and passwords only. I created a new database connection, and using a connectionResolver I dynamically select which connection to query (if there’s a “@” I select the current one, otherwise I select the legacy one)

That all worked fine in dev, but when I tried to configure this in production, I was unable to proceed. The usernameStyle option of Lock is ignored because my first database is email only, and there are no way to “force” using another field.

Here we see I could theoritically use usernameStyle: https://github.com/auth0/lock/blob/8cebda3497724f01b21efaee45288d6c41543200/src/connection/database/login_pane.jsx

But in practice, here Lock just takes the default connection and ignores any other settings: databaseConnectionRequiresUsername

I understand that’s the documented behavior, but how then can I use my second database? Is there any workaround that doesn’t involve rewriting the whole thing?

I confess I haven’t tried it myself, but what about if you set the defaultDatabaseConnection option (https://auth0.com/docs/libraries/lock/v11/configuration#defaultdatabaseconnection-string-) with the connection that supports usernames.

The above should allow to input usernames and then may still allow for you use a connectionResolver if the input is an email.

1 Like

That works, and in hindsight, that makes sense! I do not actually want to change the default connection to the “legacy” one, but in practice it doesn’t seem to be a problem. Thanks!

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