Save user to own db after user creation

So I have a next.js application and a backend api. Im letting my users login on nextjs, then i send their token to backend and validate it with express-oauth2-jwt-bearer package, everything works fine so far. What i want to do is whenever a new user logs in, i want to create that same user in my own db. I checked the userId’s but it is something like github|111111111 which i dont like, so i was trying to figure out is there way to change it to uuid or something like that. Also what is my best bet to achieve the user creations flow on my backend ? It doesnt have to be right after the user is created, maybe i can put a middle ware to my backend when we get a request from an uncreated user in the db, we create, if user exist, we move on, is tha ttoo much overhead for every request ? Thank you in advance

Hi @kutaui

Welcome to the Auth0 Community!

My best recommendation for this approach would be to use a PostRegistration Trigger so that you connect to your own db, retrieve the user information from the event object and then make a request to your db to create the user if it does not exist. However, this is not ideal since the password is not available in the event object of a trigger.

Otherwise, as you have mentioned, if you would decode the token and retrieve the user’s login information in order to check if the user exists and then create them if necessary in your own database.

The ideal approach for this use case would be to use a Custom Database connection in order for users to authenticate against your database or have those users added to the database once they are created on Auth0’s side. The feature to use your own personal user store would require you to have a Professional plan on your tenant.

If you have any other questions, let me know!

Kind Regards,
Nik