Build a custom flow for switching organizations
This guide will demonstrate how to use Clerk's API to build a custom flow for switching between organizations.
The following example:
- Uses the
useOrganizationList()
hook to getmemberships
, which is a list of the current user's organization memberships.memberships
returnsdata
, which is an array ofOrganizationMembership
objects. - Maps over the
data
array to display the user's organization memberships in a list. - Provides a button that calls
setActive()
to set the selected organization as the active organization. - Provides a button to load more organizations if there are more available. The
data
array is paginated and will only return the first 10 results, so thefetchNext()
method is used to load more organizations if they are available.
This example is written for Next.js App Router but can be adapted for any React meta framework, such as Remix.
The following example:
- Calls the
getOrganizationMemberships()
method to retrieve the list of organizations the current user is a part of. This method returnsdata
, which is an array ofOrganizationMembership
objects. - Maps over the
data
array to display the user's organization memberships in a list. - Provides a button that calls
setActive()
to set the selected organization as the active organization.
Use the tabs to view the code necessary for the index.html
and main.js
files.
Feedback
Last updated on