Post-login event.organization is undefined

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!

For the organization field to be populated, they need to use the context of the organization to sign in.
This means either sending the organization query string to /authorize or by having the user type in their organization name in the organization prompt.

The organization prompt is a configuration option on the application. You need to set the application to only team members of organizations to enable it.

1 Like

Thanks for jumping in @josiah_devizia!

Some more on authenticating users in the context of an organization, but outside of the scope of Universal Login:

1 Like

Thank you so much, both! :slight_smile:

2 Likes

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.