Organizations is not supported together with primary user modifications

I’m trying to link account with post login trigger automatically where I check the existing user with email and link users which have an existing identity. The linking works as expected but when I call api.authentication.setPrimaryUser I get an error saying Organizations is not supported together with primary user modifications, I guess this is because we have enabled auto-registration in one of our organisations.

Is there a way to resolve this? since it does work on second login but when the action performs linking the users in the first login transaction, it fails the login with the said error. I could not find this error documented anywhere so any help is appreciated. :sweat_smile:

Reference flow:

  1. Existing user = abc@abc.com via database connection belongs to ABC organisation
  2. New user = abc@abc.com via google connection now belongs to both ABC + Org1 (auto-membership organisation)
  3. Action linking works but returns an error of Organizations is not supported together with primary user modifications when login flow is completed hence, login fails at the end.
  4. It does work as intended on second login

Reference code for post login action:

const management = new ManagementClient({
      domain: "**********",
      clientId: "**********",
      clientSecret: "*************,
      audience: "<domain>/api/v2/"
  });
  try {
    const { data: users } = await management.usersByEmail.getByEmail({email: event.user.email})
    if (users.length == 2) {
      console.log("Multiple identities detected, attempting account linking.")
      console.log("User id of primary =" + users[0].user_id);
      console.log("User id of secondary =" + event.user.user_id);
      await management.users.link({id: users[0].user_id}, {provider: event.connection.name, user_id: event.user.user_id});
      api.authentication.setPrimaryUser(users[0].user_id);
    } else if (users.length > 2) {
      console.log("More than one identities detected, instead of crashing skip logic")
    }
  } catch (e) {
    console.log(e);
  }
1 Like

Hi @deepakmoveai, did you were able to resolve this issue? I am also getting a similar error

Hi @nandanpandey10, I ended up speaking with Auth0 support directly and was informed that currently they don’t support manual account linking while using organisations at the same time.

This led us to disable account linking altogether for our usecase. Hopefully this is supported by Auth0 in the near future.