Create an organization
Learn how to create an organization in your Clerk instance
Overview
Organizations are created by your end users. Whichever signed-in user creates an organization takes on the admin role for that organization.
The only required parameter when creating a new organization is the organization name, which can be any string. In React and Next.js applications, the useOrganizationList()
hook returns the createOrganization
method. In ClerkJS, the same method is available directly on the Clerk
object.
The organization name can be updated by calling the organization.update()
method.
When creating an organization, you can specify an optional slug for the new organization. If provided, the organization slug can contain only lowercase alphanumeric characters (letters and digits) and the dash "-". Organization slugs must be unique for the instance.
Using the Organizations Backend API, you can provide additional metadata for the organization and set custom attributes. Organizations support both private and public metadata. Private metadata can only be accessed from the Backend API. Public metadata can be accessed from the Backend API, and are read-only from the Frontend API.
Usage
Create a new organization
1// Form to create a new organization. The current user2// will become the organization administrator.3import { useOrganizationList } from "@clerk/nextjs";4import { FormEventHandler, useState } from "react";56export default function CreateOrganization() {7const { createOrganization } = useOrganizationList();8const [organizationName, setOrganizationName] = useState("");910const handleSubmit: FormEventHandler<HTMLFormElement> = (e) => {11e.preventDefault();12createOrganization({ name: organizationName });13setOrganizationName("");14};1516return (17<form onSubmit={handleSubmit}>18<input19type="text"20name="organizationName"21value={organizationName}22onChange={(e) => setOrganizationName(e.currentTarget.value)}23/>24<button type="submit">Create organization</button>25</form>26);27}28
1// Form to create a new organization. The current user2// will become the organization administrator.3import { useOrganizationList } from "@clerk/clerk-react";4import { FormEventHandler, useState } from "react";56export default function CreateOrganization() {7const { createOrganization } = useOrganizationList();8const [organizationName, setOrganizationName] = useState("");910const handleSubmit: FormEventHandler<HTMLFormElement> = (e) => {11e.preventDefault();12createOrganization({ name: organizationName });13setOrganizationName("");14};1516return (17<form onSubmit={handleSubmit}>18<input19type="text"20name="organizationName"21value={organizationName}22onChange={(e) => setOrganizationName(e.currentTarget.value)}23/>24<button type="submit">Create organization</button>25</form>26);27}28
1<!-- Form to create an organization -->2<form id="new_organization">3<div>4<label>Name</label>5<br />6<input name="name" />7</div>8<button>Create organization</button>9</form>1011<script>12const form = document.getElementById("new_organization");13form.addEventListener('submit', function(e) {14e.preventDefault();15const inputEl = form.getElementsByTagName("input")[0];16if (!inputEl) {17return;18}19try {20await window.Clerk.createOrganization({ name: inputEl.value });21} catch (err) {22console.error(err);23}24});25</script>26
Update organization name
1// pages/organizations/[id]/edit.js2import { useState, useEffect } from 'react';3import { useRouter } from 'next/router';4import { useOrganization } from '@clerk/nextjs';56export default function EditOrganization() {7const [name, setName] = useState('');89const router = useRouter();1011const { organization } = useOrganization();1213useEffect(() => {14if (!organization) {15return;16}17setName(organization.name);18}, [organization]);1920async function submit(e) {21e.preventDefault();22try {23await organization.update({ name });24router.push(`/organizations/${organization.id}`);25} catch (err) {26console.error(err);27}28}2930if (!organization) {31return null;32}3334return (35<div>36<h2>Edit organization</h2>37<form onSubmit={submit}>38<div>39<label>Name</label>40<br />41<input42name="name"43value={name}44onChange={(e) => setName(e.target.value)}45/>46</div>47<button>Save</button>48</form>49</div>50);51}52
1import { useState, useEffect } from 'react';2import { useOrganization } from '@clerk/react';34export default function EditOrganization({ organizationId }) {5const [name, setName] = useState('');67const { organization } = useOrganization();89useEffect(() => {10if (!organization) {11return;12}13setName(organization.name);14}, [organization]);1516async function submit(e) {17e.preventDefault();18try {19await organization.update({ name });20router.push(`/organizations/${organization.id}`);21} catch (err) {22console.error(err);23}24}2526if (!organization) {27return null;28}2930return (31<div>32<h2>Edit organization</h2>33<form onSubmit={submit}>34<div>35<label>Name</label>36<br />37<input38name="name"39value={name}40onChange={(e) => setName(e.target.value)}41/>42</div>43<button>Save</button>44</form>45</div>46);47}48
1<form id="edit_organization">2<div>3<label>Name</label>4<br />5<input name="name" />6</div>7<button>Save</button>8</form>910<script>11async function init() {12// This is the current organization ID.13const organizationId = "org_XXXXXXX";14const organizationMemberships = await window.Clerk.getOrganizationMemberships()15const currentMembership = organizationMemberships.find(membership16=> membership.organization.id === organizationId);17const currentOrganization = currentMembership.organization;1819if (!currentOrganization) {20return;21}2223editOrganization(currentOrganization);24}2526async function editOrganization(organization) {27const form = document.getElementById("edit_organization");28const inputEl = form.getElementsByTagName("input")[0];29if (inputEl) {30inputEl.value = organization.name;31}3233form.addEventListener('submit', function(e) {34e.preventDefault();35const inputEl = form.getElementsByTagName("input")[0];36if (!inputEl) {37return;38}39try {40await organization.update({ name: inputEl.value });41} catch (err) {42console.error(err);43}44});45}4647init();48</script>