# Having all users be part of an organization

**URL:** <https://community.auth0.com/t/having-all-users-be-part-of-an-organization/192021>\
**Category:** Get Help\
**Tags:** identifier-first, login-experience\
**Created:** [September 17, 2025, 11:26am UTC](https://community.auth0.com/t/having-all-users-be-part-of-an-organization/192021 "2025-09-17T11:26:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![eric.vallsg](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/eric.vallsg/32/66488_2.png) [@eric.vallsg](https://community.auth0.com/u/eric.vallsg)\
**Post date:** [September 17, 2025, 11:26am UTC](https://community.auth0.com/t/having-all-users-be-part-of-an-organization/192021/1 "2025-09-17T11:26:35Z")

</div>

I am building a B2B and B2C SaaS with a UX similar to OpenAI dashboard.

A user can sign up for free (using password, or google), but I want all users to be part of an organization where they are the only ones in. I need this because I want all the resources a user creates inside my SaaS to be related to an organization, not to a user, so that in case this user finally wants to turn into an organization, my system is already ready for that. So on sign up, I’d like every user to be inside their own ‘personal’ organization for which they can change the name and add other members.

What is the correct way to do this? When choosing the Login Experience in the application settings I understand I need the ‘Business Users’ options (so only allow login inside an org) but I don’t understand how/when to create the organization for that user so that they can log in correctly for the first time (and every time since then) without me needing to create the organization and sending them an invite link (users have to be able to sign up directly from my page and not have to wait to login). If I use the ‘Both’ option in the Login Experience setting, users will signing in without an org which I don’t want…

Thanks!

---

<div class="post-metadata">

**Author:** ![eric.vallsg](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/eric.vallsg/32/66488_2.png) [@eric.vallsg](https://community.auth0.com/u/eric.vallsg)\
**Post date:** [September 17, 2025, 11:30am UTC](https://community.auth0.com/t/having-all-users-be-part-of-an-organization/192021/2 "2025-09-17T11:30:21Z")

</div>

As an addition, I am building an SPA (react)

---

<div class="post-metadata">

**Author:** ![vlad.murarasu](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/vlad.murarasu/32/72793_2.png) [@vlad.murarasu](https://community.auth0.com/u/vlad.murarasu)\
**Post date:** [September 17, 2025, 1:51pm UTC](https://community.auth0.com/t/having-all-users-be-part-of-an-organization/192021/4 "2025-09-17T13:51:48Z")

</div>

Hi @eric.vallsg,

Welcome to the Auth0 Community!

You can achieve this self-service signup flow, where every user gets their own “personal” organization, by using an **Auth0 Action**. Specifically, a **Post User Registration** Action will trigger after a user signs up, automatically creating an organization and assigning the new user. This allows you to use the “Business Users” login experience you want.

You’ll have to create a custom Action that uses the Auth0 Management API to create an organization for each new user.

#### Step 1: Create a Machine-to-Machine (M2M) Application for the Management API

Actions need permission to call the Management API.

1. Go to your Auth0 Dashboard \> **Applications** \> **Applications** and click **Create Application**.
2. Choose **Machine to Machine Applications** and give it a name like “Actions Management API Client”.
3. Select the **Auth0 Management API** from the dropdown list.
4. Grant the following permissions, which are the minimum required for this task:

- `create:organizations`
- `create:organization_members`
- `create:organization_member_roles` (if you want to assign a role like ‘admin’)

1. Click **Authorize**. Keep this page open, as you’ll need the **Client ID** and **Client Secret** in the next step.

#### Step 2: Create the Post User Registration Action

1. In the Dashboard, navigate to **Actions** \> **Library**.
2. Click **Create Action** \> **Create Custom Action**.
3. Give it a name (e.g., “Create Personal Organization on Signup”), select the **Post User Registration** trigger, and click **Create**.
4. In the editor that appears, add the M2M application’s credentials as **Secrets**.

- Click the **key icon** on the left.
- Add a secret named `M2M_CLIENT_ID` and paste the Client ID from Step 1.
- Add another secret named `M2M_CLIENT_SECRET` and paste the Client Secret.

1. Now, add the `auth0-management` package as a **Dependency**.

- Click the **cube icon** on the left.
- Add `auth0` as a dependency. The version will populate automatically.

1. Paste the following code into the `onExecutePostUserRegistration` function. This code creates an organization and adds the new user as a member.

```javascript
/**
* Handler that will be called during the execution of a PostUserRegistration flow.
*
* @param {Event} event - Details about the user and the context in which they are logging in.
* @param {PostUserRegistrationAPI} api - Interface whose methods can be used to change the behavior of the PostUserRegistration flow.
*/
exports.onExecutePostUserRegistration = async (event, api) => {
  const { ManagementClient } = require('auth0');

  // Do not run this Action for connections that should be skipped.
  // E.g., you might not want this for an existing B2B database connection.
  // const connectionsToSkip = ['some-legacy-connection'];
  // if (connectionsToSkip.includes(event.connection.name)) {
  // return;
  // }

  const auth0 = new ManagementClient({
    domain: event.secrets.AUTH0_DOMAIN, // This secret is automatically available
    clientId: event.secrets.M2M_CLIENT_ID,
    clientSecret: event.secrets.M2M_CLIENT_SECRET,
  });

  try {
    // 1. Create the new organization
    // Using the user's ID in the 'name' ensures it is unique.
    const newOrg = await auth0.organizations.create({
      name: `personal-org-${event.user.user_id}`,
      display_name: `${event.user.given_name || event.user.email}'s Team`
    });

    // 2. Add the user to the newly created organization as an admin
    await auth0.organizations.addMembers(
      { id: newOrg.data.id },
      { members: [event.user.user_id] }
    );
    
    // You could also assign a specific role here if you have one defined.
    // This assumes a role with the ID 'rol_...' has been created.
    // await auth0.organizations.addMemberRoles(
    // { id: newOrg.data.id, user_id: event.user.user_id },
    // { roles: ['rol_...'] }
    // );

  } catch (err) {
    console.error(`Error creating personal org for user ${event.user.user_id}: ${err}`);
  }
};

```

1. Click **Deploy**.

#### Step 3: Add the Action to the Flow

1. Navigate to **Actions** \> **Triggers**.
2. Select the **Post User Registration** flow.
3. Drag your newly created Action from the “Custom” tab into the flow.
4. Click **Apply**.

Now, when any new user signs up, this Action will run, and they will be placed into their own organization automatically. You can safely set your Application’s Login Experience to “Business Users.”

If you have any further questions, feel free to reach out!

Have a good one,  
Vlad

---

<div class="post-metadata">

**Author:** ![eric.vallsg](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/eric.vallsg/32/66488_2.png) [@eric.vallsg](https://community.auth0.com/u/eric.vallsg)\
**Post date:** [September 17, 2025, 2:38pm UTC](https://community.auth0.com/t/having-all-users-be-part-of-an-organization/192021/5 "2025-09-17T14:38:18Z")

</div>

Thanks for the detailed answer! I read in the docs or somewhere that the PostUserRegistration action is not executed if a user signs up with Google (or other social logins). Is that true? It is important for us to allow Google sign ups and others you already support

---

<div class="post-metadata">

**Author:** ![vlad.murarasu](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/vlad.murarasu/32/72793_2.png) [@vlad.murarasu](https://community.auth0.com/u/vlad.murarasu)\
**Post date:** [September 17, 2025, 3:41pm UTC](https://community.auth0.com/t/having-all-users-be-part-of-an-organization/192021/6 "2025-09-17T15:41:15Z")

</div>

Hi @eric.vallsg,

Yes, that is true, the Pre-user Registration and Pre-user Registration triggers only work with the database and passwordless connections. The social connections work with the Post Login trigger, but the user will be forbidden from the app on their first login.

You can set the type of users to `Both` instead of `Business Users` and use a Post-Login trigger instead of a Post-user Registration trigger. This way, users will still be able to access your app before being assigned to an organization, and you will be able to assign users to their respective organizations after login instead of before, which will make social connections work as well.

I hope this is a good solution for your use case.

Have a good one,  
Vlad

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [October 1, 2025, 3:41pm UTC](https://community.auth0.com/t/having-all-users-be-part-of-an-organization/192021/7 "2025-10-01T15:41:35Z")

</div>

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