JavaScript Domain methods Organization domain methods
These methods on the Organization
object allow you to manage the domains of an organization.
The following examples assume:
Creates a new domain for the currently active organization. Returns an OrganizationDomain
object.
function createDomain (domainName : string ) : Promise < OrganizationDomainResource >
Name domainName
Type string
Description The domain name that will be added to the organization.
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)
}
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
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)
}
Retrieves a domain for an organization based on the given domain ID. Returns an OrganizationDomain
object.
function getDomain (params : GetDomainParams ) : Promise < OrganizationDomain >
Name domainId
Type string Description The ID of the domain that will be fetched.
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)
}
Last updated on Jan 21, 2025