An "email link" is a link that, when visited, will automatically authenticate your user so that they can perform some action on your site with less friction than if they had to sign in manually. You can create email links with Clerk by generating a sign-in token.
Common use cases include:
Welcome emails when users are added off a waitlist
Promotional emails for users
Recovering abandoned carts
Surveys or questionnaires
This guide will demonstrate how to generate a sign-in token and use it to sign in a user.
Sign-in tokens are JWTs that can be used to sign in to an application without specifying any credentials. A sign-in token can be used once, and can be consumed from the Frontend API using the ticket strategy, which is demonstrated in the following example.
Note
By default, sign-in tokens expire in 30 days. You can optionally specify a different duration in seconds using the expires_in_seconds property.
The following example demonstrates a cURL request that creates a valid sign-in token:
This will return a url property, which can be used as your email link. Keep in mind that this link will use the Account Portal sign-in page to sign in the user.
If you would rather use your own sign-in page, you can use the token property that is returned. Add the token as a query param in any link, such as the following example:
To handle email links with sign-in tokens, you must set up a page in your frontend that detects the token, signs the user in, and performs any additional actions you need.
The following example demonstrates basic code that detects a token in the URL query params and uses it to initiate a sign-in with Clerk: