Is it possible to use the Auth0 db and a custom external db to store user data at sign up?

Ready to post? :mag: First, try searching for your answer.
Hi I just started trying to set up Auth0 instead of AWS Cognito for a project as Cognito was very cumbersome I found.

I was wondering if its possible to have new user signups automatically go to my external MongoDB while also having them stored in the Auth0 DB too at the same time? Im guessing its possible by calling one of the management APIs and passing the user object data to my DB after a new sign up on the client side, but I was wondering if it was possible to have this happen automatically via the dashboard, my understanding was that as regards the dashboard management of user data db stores I had to choose either between using the built in Auth0 DB or my own custom one and not both? I hope my question makes sense, Im still new at this so apologies, thanks very much.

Hi @david.doyle7 ,

The common scenario is that users are authenticated against the external database credentials and during the first (after integrating with Auth0) login, being migrated to the Auth0 hosted user pool (called here Username-Password-Authentication).

The process is called Lazy migration and is described here - please take a look and let us know if you have further questions :slight_smile:

Thanks so much for the reply @marcelina.barycka . So after a login attempt auth0 checks against my external db first and if the user is not there it will create a new user in both the internal and external db? I hope i have it correct, thanks. My circumstance is that I have no users at present but each time one is created i need to it be in auth0s db and my mongoDB if that makes sense. I was hoping after a signup the user data would propagate to MongoDB from Auth0 or vice versa.

Thanks for clarifying @david.doyle7.

If the user is present in your MongoDB and not in Auth0, it will be created in Auth0 during login. But the lazy migration doesn’t work the other way around.

If you need to maintain both user pools, you can periodically export the list from Auth0 and import it to the external database. For this purpose, you can use our Management API. Here is a doc on that.

Let me know if you have more questions on that :slight_smile:

Thanks for the reply @marcelina.barycka , I think i’m a bit confused. I have my react app running with the Auth0 login and signup UI working. When I sign up via this UI i see a new user being created in the Auth0 dashboard users section (for my Username-Password-Authentication DB). I would like these new users to also be added to my mongodb database. Id like the react UI to add the user to both databases. Should I set the react app to call the create user action for a custom db that i create on auth0 after a sign up via to the UI to add the new user to the mongodb. Or can i get the Username-Password-Authentication DB thats created on tenant creation to send the user data to mongo db when a user is created??
I hope this makes sense, is there a normal procedure that most people follow to achieve what im looking for? Would creating a flow on teh dashboard achieve this ?
Thanks very much for the help, I really appreciate it.

I found this answer helpful and I combined the script here : How to add users to mongoDB when new user's sign in - #2 by ax0nic. ( You can swap out his MONGO_SECRET for your own connections string that you get from your mongodb dashboard

with the template one given in the actions section :

Also the script from this post will do the same in case anyone else ends up stuck too: Store Google authenticated users into a custom

Sorry for the bother ! Thanks

I should also say that this only works for people signing in without using social sign in with Google or another provider. In that case the user only gets added to the Auth0 DB

1 Like

Right, Actions! Beautiful, thanks for sharing!

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