āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā ā š shadcn/directory/clerk/clerk-docs/guides/users/inviting ā āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā
Inviting users to your Clerk application allows you to onboard new users seamlessly by sending them a unique invitation link.
Once you create an invitation, Clerk sends an email to the invited user with a unique invitation link. When the user visits the invitation link, they will be redirected to the Account Portal sign-up page and their email address will be automatically verified. If you want to redirect the user to a specific page in your application, you can specify a redirect URL when creating the invitation.
Invitations expire after a month. If the user clicks on an expired invitation, they will get redirected to the application's sign-up page and will have to go through the normal sign-up flow. Their email address will not be auto-verified.
[!TIP] Invitations are only used to invite users to your application. The application will still be available to everyone even without an invitation. If you're looking to restrict access to invited users only, refer to the Restricted sign-up mode.
You can create an invitation in the Clerk Dashboard or using the Backend API.
To invite users, navigate to the Users page from the top-level menu, then select the Invitations tab. Select Invite user and enter the email address of the person you want to invite. Optionally, set an expiration date for the invitation. Once you've entered the necessary details, select Send invite to send the invitation email.
[!TIP] The same page will be available through the top-level menu, when you are in the Restricted sign-up mode.
You can either use a cURL command or the JS Backend SDK to create an invitation. Clerk's JS Backend SDK is a wrapper around the Backend API that makes it easier to interact with the API. Use the following tabs to see examples for each method.
<Tabs items={["cURL", "JS Backend SDK"]}> <Tab> The following example demonstrates how to create an invitation using cURL.
<SignedIn>
Replace the email address with the email address you want to invite. Your Clerk Secret Key is already injected into the code snippet.
</SignedIn>
<SignedOut>
Replace the email address with the email address you want to invite. Update `YOUR_SECRET_KEY` with your Clerk Secret Key which can be found on the [**API keys**](https://dashboard.clerk.com/~/api-keys) page in the Clerk Dashboard.
</SignedOut>
```bash {{ filename: 'terminal' }}
curl https://api.clerk.com/v1/invitations -X POST -d '{"email_address": "email@example.com"}' -H "Authorization:Bearer {{secret}}" -H 'Content-Type:application/json'
```
</Tab>
<Tab>
To use the JS Backend SDK to create an invitation, see the [`createInvitation()` reference](/docs/reference/backend/invitations/create-invitation).
</Tab>
</Tabs>
See the Backend API reference{{ target: '_blank' }} for an example of the response.
When you create an invitation, you can specify a redirect_url parameter. This parameter tells Clerk where to redirect the user when they visit the invitation link.
The following example demonstrates how to use cURL to create an invitation with the redirect_url set to https://www.example.com/accept-invitation:
curl https://api.clerk.com/v1/invitations -X POST -d '{"email_address": "email@example.com", "redirect_url": "https://www.example.com/accept-invitation"}' -H "Authorization:Bearer {{secret}}" -H 'Content-Type:application/json'
Once the user visits the invitation link, they will be redirected to the page you specified, which means you must handle the sign-up flow in your code for that page. You can either embed the <SignUp /> component on that page, or if the prebuilt component doesn't meet your specific needs or if you require more control over the logic, you can build a custom flow.
[!TIP]
- To test redirect URLs in your development environment, pass your port (e.g.
http://localhost:3000).- To use the Account Portal, pass the URL provided by Clerk on the Account Portal page in the Clerk Dashboard. For example,
https://prepared-phoenix-98.accounts.dev/sign-upredirects the user to the Account Portal sign-up page.
You can also add metadata to an invitation. Once the invited user signs up using the invitation link, the invitation metadata will end up in the user's public_metadata. You can find more information about user metadata in the metadata docs.
To add metadata to an invitation, you can use the public_metadata property when the invitation is created.
The following example demonstrates how to create an invitation with metadata using cURL.
<SignedIn> Replace the email address with the email address you want to invite, and the `public_metadata` with the metadata you want to add. Your Secret Key is already injected into the code snippet. </SignedIn> <SignedOut> Replace the email address with the email address you want to invite, and the `public_metadata` with the metadata you want to add. Update `YOUR_SECRET_KEY` with your Clerk Secret Key which can be found on the [**API keys**](https://dashboard.clerk.com/~/api-keys) page in the Clerk Dashboard. </SignedOut>curl https://api.clerk.com/v1/invitations -X POST -d '{"email_address": "email@example.com", "public_metadata": {"age": "21"}}' -H "Authorization:Bearer {{secret}}" -H 'Content-Type:application/json'
You can revoke an invitation at any time. Revoking an invitation prevents the user from using the invitation link that was sent to them. You can revoke an invitation in the Clerk Dashboard or using the Backend API.
To revoke an invitation, navigate to the Users page from the top-level menu, then select the Invitations tab. Find the invitation you want to revoke and select Revoke from the dropdown menu on the right.
[!TIP] The same page will be available through the top-level menu, when you are in the Restricted sign-up mode.
You can either use a cURL command or the JS Backend SDK to revoke an invitation. Use the following tabs to see examples for each method.
<Tabs items={["cURL", "JS Backend SDK"]}> <Tab> The following example demonstrates how to revoke an invitation using cURL.
<SignedIn>
Replace the `<invitation_id>` with the ID of the invitation you want to revoke. Your Secret Key is already injected into the code snippet.
</SignedIn>
<SignedOut>
Replace the `<invitation_id>` with the ID of the invitation you want to revoke and replace `YOUR_SECRET_KEY` with your Clerk Secret Key. You can find your Secret Key on the [**API keys**](https://dashboard.clerk.com/~/api-keys) page in the Clerk Dashboard.
</SignedOut>
```bash {{ filename: 'terminal' }}
curl https://api.clerk.com/v1/invitations/<invitation_id>/revoke -X POST -H "Authorization:Bearer {{secret}}" -H 'Content-Type:application/json'
```
</Tab>
<Tab>
To use the JS Backend SDK to revoke an invitation, see the [`revokeInvitation()`](/docs/reference/backend/invitations/revoke-invitation) reference documentation.
</Tab>
</Tabs>
See the Backend API reference{{ target: '_blank' }} for an example of the response.
[!WARNING] Revoking an invitation does not prevent the user from signing up on their own. If you're looking to restrict access to invited users only, refer to the Restricted sign-up mode.
Clerk's prebuilt components and Account Portal pages handle the sign-up flow for you, including the invitation flow. If Clerk's prebuilt components don't meet your specific needs or if you require more control over the logic, you can rebuild the existing Clerk flows using the Clerk API. For more information, see the custom flow for application invitations.
ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā