Store Auth0 User Reference to External DB

Hi @damand,

There are a few ways you could do this.

You can send the user ID to your own API in a Post-User Registration Hook or a Rule.

If your app only has a database connection (i.e. email/password login), you can use a Post-User Registration Hook to send the user ID to an external API.

However, the Post-User Registration Hook will only fire for database connections. If your app has multiple types of connections such as social connections (“Sign in with Google”) and a database connection (email/password), then you can use a Rule to do the same thing.

Here is an FAQ that explains how to call an external API from within a rule: How do I call my API from a rule?

Within the rule, you can make sure that the call to your API only occurs the first time a user logs in by adding this to the top of the rule:

    const count = context.stats && context.stats.loginsCount ? context.stats.loginsCount : 0;
    if (count > 1) {
        return callback(null, user, context);
    }
1 Like