Alright, sounds good. I’ll go with the rule then.
Just so others can see what I did here it is, works like a charm:
function (user, context, callback) {
var request = require('request');
if (context.stats.loginsCount === 1) {
request({
method: 'POST',
url: 'https://yourapiurl/organizations',
json: {
"name": user.user_metadata.organization
}
},
function(err, response, body) {
if (err) {
console.log('err: ', err);
callback(err);
} else {
console.log('Organization record created successfully', body.id);
user.user_metadata.organizationId = body.id;
context.idToken[configuration.NAMESPACE] = {
organizationId: body.id
};
auth0.users.updateUserMetadata(user.user_id, user.user_metadata)
.then(function(){
callback(null, user, context);
}).catch(function(err){
callback(err);
});
}
});
} else {
callback(null, user, context);
}
}