Skip to Content
You are viewing a beta version of Clerk Docs
Visit the latest docs
Clerk logo

Clerk Docs

Ctrl + K
Go to clerk.com

OrganizationInvitation

The OrganizationInvitation object is the model around an organization invitation.

Properties

NameTypeDescription
idstringA unique identifier for this organization membership.
emailAddressstringThe email address the invitation has been sent.
organizationIdstringThe organization ID of the organization this invitation is for.
publicMetadataobjectThe public metadata of the organization membership.
roleOrganizationCustomRoleKeyThe role of the current user in the organization.
status'pending' | 'accepted' | 'revoked'The status of the invitation.
createdAtDateDate of the time the membership was created.
updatedAtDateDate of the last time the membership was updated.

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.

Methods

revoke()

Revokes the invitation for the email it corresponds to.

function revoke(): Promise<OrganizationInvitation>;

revoke() returns

TypeDescription
Promise<OrganizationInvitation>This method returns a Promise which resolves to the OrganizationInvitation for the revolked invitation.

revoke() example

The following example demonstrates how to revoke an organization invitation. It first gets the list of organization invitations using getInvitations() and then revokes the first invitation in the list.

It assumes:

main.js
import Clerk from '@clerk/clerk-js'; // Initialize Clerk with your Clerk publishable key const clerk = new Clerk('{{pub_key}}'); await clerk.load(); if (clerk.user) { // Check for an active organization if (clerk.organization) { // Get list of organization invitations const { totalCount, data } = await clerk.organization.getInvitations(); const invitations = data; console.log(`Invitations:`, invitations); if (invitations.length === 0) { console.log("No invitations to revoke."); } // Revoke the first invitation in the list invitations[0].revoke() .then((res) => console.log(res)) .catch((error) => console.log(error.errors)); } else { // If there is no active organization, // mount Clerk's <OrganizationSwitcher /> // to allow the user to set an organization as active document.getElementById("app").innerHTML = ` <h2>Select an organization to set it as active</h2> <div id="org-switcher"></div> `; const orgSwitcherDiv = document.getElementById("org-switcher"); clerk.mountOrganizationSwitcher(orgSwitcherDiv); } } else { document.getElementById("app").innerHTML = ` <div id="sign-in"></div> `; const signInDiv = document.getElementById("sign-in"); clerk.mountSignIn(signInDiv); }
index.html
<div id="app"></div> <!-- Initialize Clerk with your Clerk Publishable key and Frontend API URL --> <script async crossorigin="anonymous" data-clerk-publishable-key="{{pub_key}}" src="https://{{fapi_url}}/npm/@clerk/clerk-js@latest/dist/clerk.browser.js" type="text/javascript" ></script> <script> window.addEventListener("load", async function () { await Clerk.load(); if (Clerk.user) { // Check for an active organization if (Clerk.organization) { // Get list of organization invitations const { totalCount, data } = await Clerk.organization.getInvitations(); const invitations = data; console.log(`Invitations:`, invitations); if (invitations.length === 0) { console.log("No invitations to revoke."); } // Revoke the first invitation in the list invitations[0].revoke() .then((res) => console.log(res)) .catch((error) => console.log(error.errors)); } else { // If there is no active organization, // mount Clerk's <OrganizationSwitcher /> // to allow the user to set an organization as active document.getElementById("app").innerHTML = ` <h2>Select an organization to set it as active</h2> <div id="org-switcher"></div> `; const orgSwitcherDiv = document.getElementById("org-switcher"); Clerk.mountOrganizationSwitcher(orgSwitcherDiv); } } else { document.getElementById("app").innerHTML = ` <div id="sign-in"></div> `; const signInDiv = document.getElementById("sign-in"); Clerk.mountSignIn(signInDiv); } }); </script>

Last updated on March 26, 2024

What did you think of this content?

Clerk © 2024