Invitations
Inviting users to your Clerk application begins with creating an invitation for an email address. Once the invitation is created, an email with an invitation link will be sent to the user's email address. When the user visits the invitation link, they will be redirected to the application's sign up page and their email address will be automatically verified.
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.
Creating invitations
At the moment, you can only create invitations for email addresses via the Backend API.
You can either use a cURL command or Clerk's JavaScript Backend SDK to create an invitation. Use the following tabs to see examples for each method.
The following example demonstrates how to create an invitation using cURL.
curl https://api.clerk.com/v1/invitations -X POST -d '{"email_address": "email@example.com"}' -H "Authorization:Bearer YOUR_SECRET_KEY" -H 'Content-Type:application/json'
Clerk's JavaScript Backend SDK is a wrapper around the Backend API that makes it easier to interact with the API.
To use the Backend SDK to create an invitation, see the createInvitation()
reference documentation.
Redirect URL
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/sign-up
:
curl https://api.clerk.com/v1/invitations -X POST -d '{"email_address": "email@example.com", "redirect_url": "https://www.example.com/sign-up"}' -H "Authorization:Bearer YOUR_SECRET_KEY" -H 'Content-Type:application/json'
Once the user visits the invitation link and is redirected to the specified URL, an invitation token will be appended to the URL.
Using the previous example, the URL with the invitation token would look like this:
https://www.example.com/sign-up?__clerk_ticket=.....
You can then use the invitation token to create a new sign-up.
Invitation metadata
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.
curl https://api.clerk.com/v1/invitations -X POST -d '{"email_address": "email@example.com", "public_metadata": {"age": "21"}}' -H "Authorization:Bearer YOUR_SECRET_KEY" -H 'Content-Type:application/json'
Revoking invitations
Revoking an invitation prevents the user from using the invitation link that was sent to them.
At the moment, you can only revoke invitations via the Backend API.
You can either use a cURL command or Clerk's JavaScript Backend SDK to create an invitation. Use the following tabs to see examples for each method.
The following example demonstrates how to revoke an invitation using cURL.
curl https://api.clerk.com/v1/invitations/<invitation_id>/revoke -X POST -H "Authorization:Bearer YOUR_SECRET_KEY" -H 'Content-Type:application/json'
Clerk's JavaScript Backend SDK is a wrapper around the Backend API that makes it easier to interact with the API.
To use the Backend SDK to revoke an invitation, see the revokeInvitation()
reference documentation.
Custom flow
Clerk's prebuilt components and Account Portal pages handle the sign-up flow for you, including the invitation flow. If you want to build a custom sign-up flow, see the custom flow guide.
Feedback
Last updated on