Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a guide detailing how to create orgs on users' behalf #1684

Merged
merged 12 commits into from
Nov 15, 2024
39 changes: 39 additions & 0 deletions docs/guides/creating-orgs-for-users.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
title: Recommended Architecture for Creating Organizations on Users' Behalf
description: Learn how to architectect your application to create organizations on users' behalf without running into rate limits and billing issues.
Copy link
Contributor

@victoriaxyz victoriaxyz Nov 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
title: Recommended Architecture for Creating Organizations on Users' Behalf
description: Learn how to architectect your application to create organizations on users' behalf without running into rate limits and billing issues.
title: Create organizations on behalf of users
description: Learn how to architect your application to create organizations on behalf of users while avoiding rate limits and billing issues.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would have to be like "Creating organizations on behalf of users" or something for clarity if you want to shorten it

---

In some cases, you may want the onboarding you your application to include the creation of an organization on the user's behalf. This could be for a number of reasons, such as:

- You would like for users to your application to be manually onboarded by sales staff and sent an invite to join via an organization created for them.
- Your application only makes sense if the user is part of an organization, and you want to create the organization on the user's behalf as part of the onboarding process.
- You would like to have an "admin account" that has access to all organizations across your application, and can achieve this easily by creating an organization on the user's behalf, rather than allowing the user to create their own organization.

If this sounds like it fits your use case, this guide will walk you through how to architect your application in this way without running into unexpected rate limits or billing issues, which can be a common problem when creating organizations on behalf of users with Clerk.
jescalan marked this conversation as resolved.
Show resolved Hide resolved

## Recommended Flow

The recommended approach to ensuring that all users are in an organization is to implement an [onboarding flow](/docs/guides/add-onboarding-flow) in which it's required to create an organization before the user is able to access the application. You can use tools like the [`<CreateOrganization>` component](/docs/components/organization/create-organization) to allow the user to create and name their own organization, or you can use Clerk's [Backend API](/docs/reference/backend-api/tag/Organizations#operation/CreateOrganization) or one of our backend SDKs like the [JS Backend SDK](/docs/references/backend/organization/create-organization) to create an organization on the user's behalf and name it as you'd like.

If you'd like to have the your onboarding flow involve the user being invited to join your app via an email, you can use Clerk's [invitation functionality](/docs/users/invitations) to accomplish this. So the overall flow would look as such:

- User receives an invitation to join your application
- Upon clicking the invitation, user registers their account and enters the onboarding flow
- User creates an organization as part of the onboarding flow, and is able to invite colleagues if relevant
- You now have a user that can access your application and is guaranteed to be in an organization

If you'd also like to enable users to join an existing organization that matches their email domain if one exists, as an alternative to creating a new organization, you can use Clerk's [verified domains](/docs/organizations/verified-domains) feature to accomplish this.
jescalan marked this conversation as resolved.
Show resolved Hide resolved

## You'd like admin access to all organizations in your app

The easiest way to grant someone on your team admin access to all organizations in your app is to add them as a member to organization on clerk.com. Through Clerk's dashboard, you can see all of the organizations for each of your apps, and take administrative actions, such as adding or removing members, renaming, or deleting an organization.

If for some reason this is not an option, you can use Clerk's [Backend API](/docs/reference/backend-api) or one of our backend SDKs like the [JS Backend SDK](/docs/references/backend/overview), alongside [roles and permissions](/docs/organizations/roles-permissions) to create a custom admin dashboard through which authorized users can can take adminstrative actions for organizations.
jescalan marked this conversation as resolved.
Show resolved Hide resolved

## Not recommended: using an admin account to create organizations for users

Although it may seem like a reasonable option, we strongly recommend against using a single admin account to create organizations on the behalf of users. Generally, this is because it can create unexpectedly high costs due to the way that organizations are billed. Let's walk through an example to see why.

Imagine that you have an admin account that is configured to create organizations on a user's behalf during onboarding, then send an invitation to the user to join the organization. When the user accepts the invitation, their organization has an unneccessary extra admin account in it, and additionally at that point, the organization has two monthly active users (MAUs), which make it a active organization. All [Clerk plans](https://clerk.com/pricing) come with 100 active organizations included for free, but over that limit, organizations are billed at $1/month/org. This means that for every user that is created in your app, they have an active organization automatically, because of the fact that the admin account is also in the organization. This tends to result in much higher costs than if users' organizations are created without an admin account included. Additionally, it's generally a nicer user experience for users not to have extra admin accounts in their organizations.

If you have an architecture scenario that isn't covered here or feel that it's critical to create organizations using an admin account, please reach out to us at [[email protected]](mailto:[email protected]) and we'll be happy to help think through a suitable solution.
jescalan marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 4 additions & 0 deletions docs/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@
{
"title": "Override Clerk interfaces with custom types",
"href": "/docs/guides/custom-types"
},
{
"title": "Creating Organizations on Users' Behalf",
jescalan marked this conversation as resolved.
Show resolved Hide resolved
"href": "/docs/guides/creating-orgs-for-users"
}
]
]
Expand Down
Loading