Skip to content

Instantly share code, notes, and snippets.

@da-blog
Created August 4, 2023 20:40
Show Gist options
  • Save da-blog/a15d25105e3fc0531735c8d41a31c71b to your computer and use it in GitHub Desktop.
Save da-blog/a15d25105e3fc0531735c8d41a31c71b to your computer and use it in GitHub Desktop.
function (user, context, callback) {
// Only support users with a verified email address
if (!user.email || !user.email_verified) {
return callback(null, user, context);
}
// Only onboard the user to the ledger once
if (user.app_metadata && user.app_metadata.daml_ledger_api) {
return callback(null, user, context);
}
// Construct the the DAML party identifier from the email
// We could also use a random UUID string here
var partyIdentifier = user.email.replace(/\W/gi, "-");
// TODO: Allocated the party on the ledger
// This step is not necessary for the sandbox, as it has an
// open world of parties.
// Save the new app metadata
user.app_metadata = user.app_metadata || {};
user.app_metadata.daml_ledger_api = {
partyIdentifier
};
auth0.users.updateAppMetadata(user.user_id, user.app_metadata)
.then(function(){
callback(null, user, context);
})
.catch(function(err){
callback(err);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment