Organization membership methods
These methods on the Organization
object allow you to manage the memberships of an organization.
To see how all these methods work together, see the comprehensive example.
getMemberships()
Retrieves the list of memberships for the currently active organization.
- Name
initialPage?
- Type
number
- Description
A number that can be used to skip the first n-1 pages. For example, if
initialPage
is set to 10, it is will skip the first 9 pages and will fetch the 10th page.
- Name
pageSize?
- Type
number
- Description
A number that indicates the maximum number of results that should be returned for a specific page.
- Name
role?
- Type
OrganizationCustomRoleKey[]
- Description
The roles of memberships that will be included in the response.
OrganizationCustomRoleKey
OrganizationCustomRoleKey
is a string that represents the user's role in the organization. Clerk provides the default roles org:admin
and org:member
. However, you can create custom roles as well.
Returns
Type | Description |
---|---|
Promise<ClerkPaginatedResponse<OrganizationMembership>> | This method returns a Promise that resolves to a ClerkPaginatedResponse of OrganizationMembership objects. |
addMember()
Adds a user as a member to an organization. A user can only be added to an organization if they are not already a member of it and if they already exist in the same instance as the organization.
Only administrators can add members to an organization.
- Name
userId
- Type
string
- Description
The ID of the user that will be added as a member to the organization.
- Name
role
- Type
string
- Description
The role that the user will have in the organization.
Returns
Type | Description |
---|---|
Promise<OrganizationMembership> | This method returns a Promise that resolves to the OrganizationMembership object. |
updateMember()
Updates a member. Currently, only a user's role can be updated.
- Name
userId
- Type
string
- Description
The user identifier.
- Name
role
- Type
string
- Description
The role of the new member.
Returns
Type | Description |
---|---|
Promise<OrganizationMembership> | This method returns a Promise that resolves to the updated OrganizationMembership object. |
removeMember()
Removes a member from the organization based on the userId
.
- Name
userId
- Type
string
- Description
The user identifier.
Returns
Type | Description |
---|---|
Promise<OrganizationMembership> | This method returns a Promise that resolves to the removed OrganizationMembership object. |
Organization membership methods example
The following example demonstrates how to use the organization membership methods to manage the members of an organization. To ease the development process, the response or error message of a method will be displayed on the user interface.
Feedback
Last updated on