Accept organization invitations
When a user visits an organization invitation link, and no custom redirect URL was specified, and they have an account for your application, then they will be redirected to Clerk's Account Portal sign-in page. If they do not have an account for your application, they will be redirected to Clerk's Account Portal sign-up page.
However, if you specified a redirect URL when creating the invitation, you must handle the sign-up and sign-in flows in your code for that page. You can either embed Clerk's <SignIn /
> 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 rebuild the existing Clerk flows using the Clerk API.
This guide will demonstrate how to build custom flows to handle organization invitations.
Create the sign-up flow
Once the user visits the invitation link and is redirected to the specified URL, the query parameters __clerk_ticket
and __clerk_status
will be appended to the URL.
For example, if the redirect URL was https://www.example.com/accept-invitation
, the URL that the user would be redirected to would be https://www.example.com/accept-invitation?__clerk_ticket=.....
.
The __clerk_ticket
query parameter contains the ticket token, which is essential for completing the organization invitation flow. You'll use this token in your code for the page that you redirected the user to.
The __clerk_status
query parameter is the outcome of the ticket verification and will contain one of three values:
sign_in
indicates the user already exists in your application. You should create a sign-in flow using the invitation token by extracting the token from the URL and passing it to thesignIn.create()
method.sign_up
indicates the user doesn't already exist in your application. You should create a sign-up flow using the invitation token by extracting the token from the URL and passing it to thesignUp.create()
method.complete
indicates the user already exists in your application, and was signed in. The flow has been completed and no further actions are required.
The following example demonstrates how to handle both sign-up and sign-in flows using the invitation token:
- It extracts the token from the URL.
- It passes the token to either
signUp.create()
orsignIn.create()
, depending on the__clerk_status
. - It includes optional fields for collecting additional user information during sign-up. You can modify or remove these fields as needed for your application.
Feedback
Last updated on