I am trying to write an action to add custom claims around the User’s Organization data. However, event.organization
is coming through as undefined. I am logging in with a user who is a member of an Organization, through a connection type that is valid on the Organization. I am not sure why the organization is coming through as undefined – I also cannot find anywhere in the documentation that describes the conditions in which this data is populated.
Code below:
exports.onExecutePostLogin = async (event, api) => {
// Set custom namespace
const namespace = 'https://api.NAMESPACE.com';
// Assert organization is defined
const organization = event?.organization;
if (!organization) {
// console.log(`No organization found: ${JSON.stringify(event)}`);
console.log(event.organization);
return;
};
// Get properties from organization
const { id, display_name } = organization;
if (event.authorization) {
// Set claims
if (id) api.idToken.setCustomClaim(`${namespace}/organization_id`, id);
if (display_name) api.idToken.setCustomClaim(`${namespace}/organization_name`, display_name);
}
};
Logs come through as: undefined
Any help is much appreciated! Thank you!