Invite users to an organization
Learn how to invite new users to an organization
Overview
Organization administrators have the ability to invite new users to their organization and manage those invitations. When an administrator invites a new member, an invitation email is sent out. The invitation recipient can be either an existing user of your application or a new user. If the latter is true, the user will be registered once they accept the invitation.
In React and Next.js applications, the useOrganization()
hook returns the organization
property, which is then used to call organization.inviteMember()
passing in the recipient's email address and desired role (either basic_member
or admin
).
Administrators are also able to revoke organization invitations for users that have not yet joined, which will prevent the user from becoming an organization member. This is done by calling the revoke()
method on the invitations in the invitationList
returned by the useOrganization()
hook.
Usage
An example implementation in Next.js for inviting users and revoking pending invitations:
1import { useOrganization } from '@clerk/nextjs';2import { useState } from 'react';34function InviteMember() {5const { organization } = useOrganization();6const [emailAddress, setEmailAddress] = useState('');7const [role, setRole] = useState<'basic_member' | 'admin'>('basic_member');8const [disabled, setDisabled] = useState(false);910const onSubmit = async e => {11e.preventDefault();12setDisabled(true);13await organization.inviteMember({ emailAddress, role });14setEmailAddress('');15setRole('basic_member');16setDisabled(false);17};1819return (20<form onSubmit={onSubmit}>21<input22type="text"23placeholder="Email address"24value={emailAddress}25onChange={e => setEmailAddress(e.target.value)}26/>27<label>28<input29type="radio"30checked={role === 'admin'}31onChange={() => {32setRole('admin');33}}34/>{' '}35Admin36</label>37<label>38<input39type="radio"40checked={role === 'basic_member'}41onChange={() => {42setRole('basic_member');43}}44/>{' '}45Member46</label>{' '}47<button type="submit" disabled={disabled}>48Invite49</button>50</form>51);52}5354export default function InvitationList() {55const { invitationList } = useOrganization({ invitationList: {} });5657if (!invitationList) {58return null;59}6061const revoke = async inv => {62await inv.revoke();63};6465return (66<div>67<h2>Invite member</h2>68<InviteMember />6970<h2>Pending invitations</h2>71<ul>72{invitationList.map(i => (73<li key={i.id}>74{i.emailAddress} <button onClick={() => revoke(i)}>Revoke</button>75</li>76))}77</ul>78</div>79);80}