I’ve seen articles and discussion about how to use a separate database for auth0 authentication (whether it’s using the database directly or importing user from that database into Auth0’s db), but I haven’t seen the other way around.
We have an existing database that we use for some other operation, and we need to have every existing user on Auth0 to be on that database.
Currently I have the idea of using the rule
and check if the user logs in for the first time. If that’s the case, go ahead and call an API endpoint that will trigger user creation.
say my endpoint is https://some_domain/some_endpoint/create_user
, I use the template Update User Profile in Firebase
and modify to the following
function (user, context, callback) {
if (context.stats.loginsCount > 1) return callback(null, user, context);
var url = 'https://some_domain/some_endpoint/create_user';
var api_token = 'blahblahblah';
var headers = {
'Authorization' : 'Token ' + api_token
};
request.post({
"url": url,
"useremail": user.email,
"header": headers
},
function(err, response, body) {
if (err) return callback(err);
return callback(null, user, context);
});
}
I tried to Try this rule
and there’s no message whatsoever that shows success or failure (I doubt the endpoint was ever called since if I change the endpoint to something invalid, the process of Try this rule
is still completed)
I’m wondering if this approach will work and how I can test it