Auth0 Home Blog Docs

User search capabilities while using a Custom database connection



We expecting to use Auth0 for a multi-tenant SaaS application with a legacy user data store. We will be using a custom database connection to migrate users to Auth0 data store over time.

Our architecture relies on being able to retrieve users based on information stored in metadata (as per this article app_metadata should be named just metadata if we are using a custom db connection).

Sample metadata

“tenantId”: “bfc6b109-f668-44c2-bc8f-cf119a5b81e1”,
“groupCodes”: [

We need to retrieve users based on tenantId or groupCodes for different use cases. But the action scripts listed on custom-db don’t seem to include anything for searching users.

Given that our users will span our custom db and Auth0 db for a period of time, we are looking for a consistent to perform these user searches, but I couldn’t find any documentation confirming the availability/unavailability of user search in case of custom db connections.

Could someone please clarify this for me?


Hey there,

Unfortunately this isn’t easily achievable. Auth0 database action scripts for user import only expose login and get_user for specific user journeys. The login scripts are only called during authentication if there isn’t a user in Auth0 with a matching email or username. The get_user script is used for registration and forgot password flows, like login these scripts are only called when the user does not exist in Auth0 by email/username.

To search users in Auth0 you can use the management API, but this API will only search users in Auth0. It has no mechanism for reaching out to your user store container users that have not been migrated to Auth0.

The only way I can think about doing this is to utilize Auth0’s Management API to look for the user, if one isn’t found in Auth0 then issue a second search on your legacy user store (you would need to build this functionality). Because the users are not fully imported Auth0 will not have a way to search your users.

As an aside here are some best practices when using our search API: