Event.organization is undefined when users login

i have the following action when logging in:


exports.onExecutePostLogin = async (event, api) => {
  
  const user = event.user;
  const organization = event.organization;

  const userRequire2fa = user.app_metadata && user.app_metadata.require2fa;
  const orgRequire2fa = organization?.metadata.require2fa;
  //TODO access users organization metadata. on current approach organization is undefined
 
  if (orgRequire2fa||userRequire2fa) {
    console.log(organization)
    api.multifactor.enable("any")
  }
 
};

by testing that in the Actions playground it reads the event.organization and the metadata I put there. but when testing with a real org and user associated, it is undefined

this is what is logged in auth0 actions:

{
  "action_name": "require2fa",
  "response": {
    "logs": "undefined\n",
    "stats": {
      "total_request_duration_ms": 1723,
      "total_runtime_execution_duration_ms": 1719,
      "runtime_processing_duration_ms": 1373,
      "action_duration_ms": 211,
      "runtime_external_call_duration_ms": 135,
      "boot_duration_ms": 1508,
      "network_duration_ms": 5
    }
  },
  "started_at": "2023-07-05T17:26:38.412329876Z",
  "ended_at": "2023-07-05T17:26:40.136760544Z"
}

Hey there @mateo.perez welcome to the community!

Hmm that’s interesting - Are you positive the user is logging in through an Organization? Event.organization will be undefined unless the user authenticates through an organization by way of choosing the Organization in Universal Login or constructing the authorize call manually and adding the org_id.

Let us know!

1 Like