Organizations let you group users with roles and permissions, enabling you to build multi-tenant B2B apps like Slack (workspaces), Linear (teams), or Vercel (projects) where users can switch between different team contexts.
The <OrganizationSwitcher /> component is the easiest way to let users create, switch between, and manage organizations. It's recommended to place it in your app's header or navigation so it's always accessible. For example:
Use Clerk's hooks to access the current organization and role within your components:
The useOrganization() hook is used to access information about the currently active organization.
The useOrganizationList() hook is used to access information about the current user's organization memberships.
exportdefaultfunctionPage() {const { organization } =useOrganization()const { userMemberships } =useOrganizationList({ userMemberships:true, })return ( <divclassName="p-8"> <h1className="text-2xl font-bold mb-4"> Welcome to the <strong>{organization?.name}</strong> organization </h1> <pclassName="mb-6"> Your role in this organization:{' '} <strong> {/* Find the organization membership that matches the currently active organization and return the role */} {userMemberships?.data?.find( (membership) =>membership.organization.id ===organization?.id, )?.role } </strong> </p> </div> )}
Clerk's JS Backend SDK provides methods for accessing organization data server-side. For example, to get information about an organization, you can use the getOrganization() method. It requires the organization ID, which can be accessed through the Auth object.
import { auth, clerkClient } from'@clerk/nextjs/server'import { OrganizationSwitcher } from'@clerk/nextjs'exportdefaultasyncfunctionPage() {// The `Auth` object gives you access to properties like `orgId`// Accessing the `Auth` object differs depending on the SDK you're using// https://clerk.com/docs/reference/backend/types/auth-object#how-to-access-the-auth-objectconst { orgId } =awaitauth()// Check if there is an active organizationif (!orgId) {return ( <> <p>Set an active organization to access this page.</p> <OrganizationSwitcher /> </> ) }// To fetch the active organization server-side,// first initialize the JS Backend SDK.// This varies depending on the SDK you're using// https://clerk.com/docs/js-backend/getting-started/quickstart// Then use the `clerkClient()` to access the `getOrganization()` methodconstclient=awaitclerkClient()constorganization=awaitclient.organizations.getOrganization({ organizationId: orgId })return <p>Hello {organization.name}</p>}
You can protect content and even entire routes based on organization membership, roles, and permissions by performing authorization checks.
In the following example, the page is restricted to authenticated users, users who have the org:admin role, and users who belong to the Acme Corp organization.
The Auth object is used to access the isSignedIn property and has() method.
The isSignedIn property is used to check if the user is signed in.
The has() method is used to check if the user has the org:admin role.
The organization name is checked to ensure it matches the required organization name. If a user is not in the required organization, the page will display a message and the <OrganizationSwitcher /> component will be rendered to allow the user to switch to the required organization.
app/protected/page.tsx
'use client'import { OrganizationSwitcher, useAuth, useOrganization } from'@clerk/nextjs'exportdefaultfunctionPage() {// The `useAuth()` hook gives you access to properties like `isSignedIn` and `has()`const { isSignedIn,has } =useAuth()const { organization } =useOrganization()// Check if the user is authenticatedif (!isSignedIn) {return <p>You must be signed in to access this page.</p> }// Check if there is an active organizationif (!organization) {return ( <> <p>Set an active organization to access this page.</p> <OrganizationSwitcher /> </> ) }// Check if the user has the `org:admin` roleif (!has({ role:'org:admin' })) {return <p>You must be an admin to access this page.</p> }// Check if organization name matches (e.g., "Acme Corp")constrequiredOrgName='Acme Corp'if (organization.name !== requiredOrgName) {return ( <> <p> This page is only accessible in the <strong>{requiredOrgName}</strong> organization. Switch to the <strong>{requiredOrgName}</strong> organization to access this page. </p> <OrganizationSwitcher /> </> ) }return ( <p> You are currently signed in as an <strong>admin</strong> in the{' '} <strong>{organization.name}</strong> organization. </p> )}
For more examples on how to perform authorization checks, see the dedicated guide.
You can protect content and even entire routes based on organization membership, roles, and permissions by performing authorization checks.
In the following example, the page is restricted to authenticated users, users who have the org:admin role, and users who belong to the Acme Corp organization.
The Auth object is used to access the isAuthenticated and orgId properties, as well as the has() method.
The isAuthenticated property is used to check if the user is authenticated.
The orgId property is used to check if there is an active organization.
The has() method is used to check if the user has the org:admin role.
The organization name is checked to ensure it matches the required organization name. If a user is not in the required organization, the page will display a message and the <OrganizationSwitcher /> component will be rendered to allow the user to switch to the required organization.
This example is written for Next.js App Router, but can be adapted to other frameworks by using the appropriate method for accessing the Auth objectClerk Icon, and the appropriate initialization for clerkClient().
app/protected/page.tsx
import { auth, clerkClient } from'@clerk/nextjs/server'import { OrganizationSwitcher } from'@clerk/nextjs'exportdefaultasyncfunctionPage() {// The `Auth` object gives you access to properties like `isAuthenticated` and `userId`// Accessing the `Auth` object differs depending on the SDK you're using// https://clerk.com/docs/reference/backend/types/auth-object#how-to-access-the-auth-objectconst { isAuthenticated,orgId,has } =awaitauth()// Check if the user is authenticatedif (!isAuthenticated) {return <p>You must be signed in to access this page.</p> }// Check if there is an active organizationif (!orgId) {return ( <> <p>Set an active organization to access this page.</p> <OrganizationSwitcher /> </> ) }// Check if the user has the `org:admin` roleif (!has({ role:'org:admin' })) {return <p>You must be an admin to access this page.</p> }// To fetch the active organization server-side,// first initialize the JS Backend SDK.// This varies depending on the SDK you're using// https://clerk.com/docs/js-backend/getting-started/quickstart// Then use the `clerkClient()` to access the `getOrganization()` methodconstclient=awaitclerkClient()constorganization=awaitclient.organizations.getOrganization({ organizationId: orgId })// Check if organization name matches (e.g., "Acme Corp")constrequiredOrgName='Acme Corp'if (organization.name !== requiredOrgName) {return ( <> <p> This page is only accessible in the <strong>{requiredOrgName}</strong> organization. Switch to the <strong>{requiredOrgName}</strong> organization to access this page. </p> <OrganizationSwitcher /> </> ) }return ( <p> You are currently signed in as an <strong>admin</strong> in the{' '} <strong>{organization.name}</strong> organization. </p> )}
For more examples on how to perform authorization checks, see the dedicated guide.
You've added Clerk organizations to your Next.js app 🎉. Ready to scale to enterprise customers?
Control access with custom roles and permissions: define granular permissions for different user types within organizations.
Onboard entire companies with verified domains: automatically invite users with approved email domains (e.g., @company.com) to join organizations without manual invitations.
Enable enterprise SSO with SAML and OIDC: let customers authenticate through their identity provider (Okta, Entra ID, Google Workspace) with unlimited connections, no per-connection fees.