Docs

Organization domain methods

These methods on the Organization object allow you to manage the domains of an organization.

The following examples assume:

createDomain()

Creates a new domain for the currently active organization.

function createDomain(domainName: string): Promise<OrganizationDomainResource>
  • Name
    domainName
    Type
    string
    Description

    The domain name that will be added to the organization.

Returns

TypeDescription
Promise<OrganizationDomain>This method returns a Promise that resolves to the OrganizationDomain for the corresponding ID.

Example

main.js
import { Clerk } from '@clerk/clerk-js'

const pubKey = import.meta.env.VITE_CLERK_PUBLISHABLE_KEY

const clerk = new Clerk(pubKey)
await clerk.load()

if (clerk.user) {
  // Check for an active organization
  if (clerk.organization) {
    await clerk.organization
      .createDomain('test-domain.com')
      .then((res) => console.log(res))
      .catch((error) => console.log('An error occurred:', 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)
}

getDomains()

Retrieves the list of domains for the currently active organization.

function getDomains(params?: GetDomainsParams): Promise<ClerkPaginatedResponse<OrganizationDomain>>
  • 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
    enrollmentMode?
    Type
    'manual_invitation' | 'automatic_invitation' | 'automatic_suggestion'
    Description

    An enrollment mode will change how new users join an organization.

Returns

TypeDescription
Promise<ClerkPaginatedResponse<OrganizationDomain>>This method returns a Promise that resolves to a ClerkPaginatedResponse of OrganizationDomain objects.

Example

main.js
import { Clerk } from '@clerk/clerk-js'

const pubKey = import.meta.env.VITE_CLERK_PUBLISHABLE_KEY

const clerk = new Clerk(pubKey)
await clerk.load()

if (clerk.user) {
  // Check for an active organization
  if (clerk.organization) {
    await clerk.organization
      .getDomains()
      .then((res) => console.log(res))
      .catch((error) => console.log('An error occurred:', 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)
}

getDomain()

Retrieves a domain for an organization based on the given domain ID.

function getDomain(params: GetDomainParams): Promise<OrganizationDomain>
  • Name
    domainId
    Type
    string
    Description

    The ID of the domain that will be fetched.

Returns

TypeDescription
Promise<OrganizationDomain>This method returns a Promise that resolves to the OrganizationDomain for the corresponding ID.

Example

main.js
import { Clerk } from '@clerk/clerk-js'

const pubKey = import.meta.env.VITE_CLERK_PUBLISHABLE_KEY

const clerk = new Clerk(pubKey)
await clerk.load()

if (clerk.user) {
  // Check for an active organization
  if (clerk.organization) {
    const domainId = 'orgdmn_123'

    await clerk.organization
      .getDomain({ domainId })
      .then((res) => console.log(`Domains:`, res))
      .catch((error) => console.log('An error occurred:', 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)
}

Feedback

What did you think of this content?

Last updated on