Auth0 Home Blog Docs

Using multiple databases for an application

database-connections
oauth2

#1

I have multiple Applications defined. Each of those applications have a seperate database with uers. What I want is an additional database, which contains "super"users who have to be able to login with every single application.

What I did was, I made an additional database at “Connections->Database”. I added the connection to every application. But when I add a user to the additional database, it states that the username or password for that user isn’t correct when I log in using the Application. When I pretend to be the user by using “Sign in as user” it works just fine. Is there a setting I’m missing?


#2

I believe you need to specify the connection. Auth0 will not automatically scan all enabled connections for you.


#3

Alright, sounds fair.

But why can I enable multiple databases per application then? And why does it automatically work with the first database I connect? I can’t implement additional code to the current functionality. Or maybe I could, but I don’t know how or where to put this ‘Lock’.


#4

You may be able to customize the hosted login page to do what you want, though someone with HLP customization experience can better answer whether that is possible and how to do it. Maybe it’s possible to add a toggle or menu allowing the person to self-identify as a superuser which then forces authentication against your second connection.

I don’t know much about your use-case but the usual way to do this is with a single database and role-based access control. Put all your users in one DB and identify superusers with something like { app_metadata.roles: [ 'superuser' ] }

Edit: “the usual way” above is a bit presumptuous of me. There likely are good use cases for multiple databases, but you’ll probably find that a single DB + roles, if it works for your use case, is much easier to manage and to code against.


#5

Interesting, I’ll look into that. Thanks!