# Post-login event.organization is undefined

**URL:** <https://community.auth0.com/t/post-login-event-organization-is-undefined/87280>\
**Category:** Get Help\
**Created:** [July 20, 2022, 2:42pm UTC](https://community.auth0.com/t/post-login-event-organization-is-undefined/87280 "2022-07-20T14:42:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![myles.murphy](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/myles.murphy/32/33738_2.png) [@myles.murphy](https://community.auth0.com/u/myles.murphy)\
**Post date:** [July 20, 2022, 2:42pm UTC](https://community.auth0.com/t/post-login-event-organization-is-undefined/87280/1 "2022-07-20T14:42:36Z")

</div>

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:

```auto
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!

---

<div class="post-metadata">

**Author:** ![josiah\_devizia](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/josiah_devizia/32/33352_2.png) [@josiah\_devizia](https://community.auth0.com/u/josiah_devizia)\
**Post date:** [July 20, 2022, 8:05pm UTC](https://community.auth0.com/t/post-login-event-organization-is-undefined/87280/3 "2022-07-20T20:05:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [July 21, 2022, 2:39am UTC](https://community.auth0.com/t/post-login-event-organization-is-undefined/87280/4 "2022-07-21T02:39:59Z")

</div>

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:

[https://community.auth0.com/t/authenticating-users-through-a-specific-organization/84679?preview\_theme\_id=30](https://community.auth0.com/t/authenticating-users-through-a-specific-organization/84679?preview_theme_id=30)

---

<div class="post-metadata">

**Author:** ![myles.murphy](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/myles.murphy/32/33738_2.png) [@myles.murphy](https://community.auth0.com/u/myles.murphy)\
**Post date:** [July 21, 2022, 1:42pm UTC](https://community.auth0.com/t/post-login-event-organization-is-undefined/87280/5 "2022-07-21T13:42:42Z")

</div>

Thank you so much, both! 🙂

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [August 5, 2022, 1:42pm UTC](https://community.auth0.com/t/post-login-event-organization-is-undefined/87280/6 "2022-08-05T13:42:48Z")

</div>

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