Auth0 Home Blog Docs

Selecting multi database connection based on email domain with auth0-spa.js

I wondering how I be able to select connection based on email domain used for login using auth0-spa-js that in fact is a very promising for SPA?

I read here https://auth0.com/docs/libraries/lock/v11/selecting-the-connection-for-multiple-logins#selecting-among-multiple-database-connections possibility to do such connectionResolver to achieve such logic with Lock.js. But how with auth0-spa-js?

Thank for your input.

1 Like

Hi @matinfo
What you are after would not be really the responsibility of auth0-spa-js.
auth0-spa-js (running in the context of your SPA) will redirect the user to your Auth0 domain to authenticate, but then the authentication (and deciding which connection to use) will happen on the Auth0 side (on the hosted login page).
If you enable customization on the hosted login page, you’ll get Lock in the default template to handle the authentication UI. In that code you can use the connectionResolver to put your own login for deciding which connection to use.

Hope that helps!

1 Like

HI @nicolas_sabena, ok, for that point, thanks.

But how I be able to passe with such logic above to the component, like this:

<Auth0Provider
connection={???}
prompt={false}
display=“page”
ui_locales={localStorage.getItem(“lng”) || config.get(“DEFAULT_LANGUAGE”)}
domain={{config.get(“AUTH.DOMAIN”)}}
client_id={config.get(“AUTH.CLIENT_ID”)}
redirect_uri={window.location.origin}
audience={config.get(“AUTH.AUDIENCE”)}
onRedirectCallback={onRedirectCallback}
>



Or connexion props in this case is not needs?

In most cases, the application (client) asking for an authentication should not be concerned with the connection that the user is going to use to authenticate, so auth0-spa-js should not need a connection parameter.

They connection should be decided on the login phase (either automatically based on the user’s email address or some other context, or by asking the user). That’s why the connectionResolver is an option that you configure in Lock, the UI login widget that runs on the hosted login page.

1 Like

@nicolas_sabena, first thank you for your fast support.

I confirm, that all work like expected :ok_hand:.

But for information, I noticed, when login window is shown, the settings of default database Username-Password-Authentication is used, settings like Disable Sign Ups.

1 Like

I also have issue on this. I have enable to databases for SPA application and API but I only use Username-Password-Authentication database only for other database users it gives Wrong Email or password. Even didn’t send an email for reset password