Skip to content

Instantly share code, notes, and snippets.

@xkisu
Created February 2, 2018 07:38
Show Gist options
  • Save xkisu/643aeb14b2621d78952f17efde0127ce to your computer and use it in GitHub Desktop.
Save xkisu/643aeb14b2621d78952f17efde0127ce to your computer and use it in GitHub Desktop.
function (user, context, callback) {
var uuid = require("uuid");
user.app_metadata = user.app_metadata || {};
var promise = Promise.resolve(1);
if (!user.app_metadata.uuid) {
user.app_metadata.uuid = uuid();
promise = auth0.users.updateAppMetadata(user.user_id, user.app_metadata);
}
promise.then(() => {
if (context.idToken) {
// Include the uuid in the issued ID token if applicable
context.idToken["http://kobu.io/uuid"] = user.app_metadata.uuid;
}
if (context.accessToken) {
// Include the uuid in the issued access token if applicable
context.accessToken["http://kobu.io/uuid"] = user.app_metadata.uuid;
}
callback(null, user, context);
}).catch(callback);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment