How to save user_id in local database?

I have Auth0 successfully authenticating my users. When the user signs up initially, I would like to create a document in my users collection in my local db (i’m using mongoDB) with the user_id. The plan is to use this user_id to reference other documents that are specific to a user. My question is how do I go about doing this. And also, is user_id a good identifier to uniquely distinguish my users? This is my first application and i’m still a little shaky on how to do this.

The available options will depend on the type of connections involved and even the requirements for how soon you need that local user record to be created.

For database connections, you could consider the post-user registration hook; this would be called immediately after the user is created/signup. If you need other connection types you can consider doing the local user record creation from within a rule with some conditional logic so that the creation is only done after the first login.

Another approach would even be to create the local user only the first time your client application makes a call to your back-end/API that requires this information.

In relation to the user identifier, in terms of uniqueness, it’s a suitable choice as that should be unique across all users within on Auth0 account.