Magic link authentication
Learn to implement magic links for passwordless sign-in, invitation-only registration, and organization member invites using one-time tokens.
Learn to implement magic links for passwordless sign-in, invitation-only registration, and organization member invites using one-time tokens.
A magic link is a passwordless authentication method where a user receives a one-time login URL via email (or SMS). Clicking the link logs them in without requiring a password.
Here are some key security features of magic links:
A magic link consists of:
For example, a magic link might look like this:
To create a magic link, you need to generate a one-time token, send it securely to the user, and then validate it when the user clicks the link.
Use Logto Management API to create a one-time token.
Sample request body payload:
After you get the one-time token, you can compose a magic link and send it to the end user's email address. The magic link should at least contain the token and the user email as parameters, and should navigate to a landing page in your own application. E.g. https://yourapp.com/landing-page.
Here's a simple example of what the magic link may look like:
Note:
The parameter names in the magic link can be fully customized. You may add additional information to the magic link based on your application's requirements, as well as encoding all the URL parameters.
After the end user clicks the magic link and navigated to your application, you can extract the token and email parameters from the URL, and then call the signIn() function from Logto SDK to trigger the auth flow.
For more details, check the Logto Docs - Magic Link (One-time Token).
Magic links can replace the first-factor authentication step, but cannot bypass Multi-Factor Authentication (MFA).
In Logto, when generating a magic link with a one-time token, you don’t need to specify whether it’s for sign-in or sign-up. We automatically determine the flow based on the email's registration status:
Logto supports the following scenarios with magic links:
Currently not supported:
Let us know if you need further customization.
For new products (e.g., AI tools) in internal testing or for internal tools, you may want to disable public registration and allow only specific users to access your app. To implement this with Logto:
Go to Console > Sign-in experience > Sign-in and sign-up > Advanced options, and toggle off "Enable user registration" to close public registration.

Collect the email addresses of the users you want to invite (e.g., via your website or recommendations from existing users).
Create and send the magic invitation link as outlined above (request the one-time token, compose the magic link, trigger authentication via Logto SDK).
Note: Set an expiration time for the invitation link. It’s recommended to make the link valid for at least one day. Use the following request body to generate the one-time token:
Send the magic link to the user’s email (e.g., https://yourapp.com/landing-page?type=registrationInvitation&token=YHwbXSXxQfL02IoxFqr1hGvkB13uTqcd&[email protected]). Customize the email template, such as:

When users click "Accept the invitation", they will automatically register for your service, even with public registration disabled. This is referred to as "Targeted user invitation".
For multi-tenant products (e.g., SaaS apps like Slack, GitHub, Vercel), provide a seamless member invitation process to manage organization memberships. Use magic links for higher conversion rates in member invitations.
Follow Logto Docs to implement organization creation, organization role-based access control, and organization management: Logto Organizations.
Set up the "Invite members" workflow in your product. Example:

Follow this guide to Invite Organization Members. Note: When inviting members, ensure the request payload includes:
context: jitOrganizationIds to specify which organization(s) the user will join.expiresIn time (e.g., 2 days or 1 week) to allow sufficient time for users to accept the invitation.Example request payload:
Send the invitation link to the user’s email (e.g., https://yourapp.com/landing-page?type=organizationMemberInvitation&token=YHwbXSXxQfL02IoxFqr1hGvkB13uTqcd&[email protected]). Customize your email template, for example:

When users click "Accept the invitation", they will automatically sign in or sign up and auto-join the organization.
What happens if a user is already signed in and clicks another magic link?
To handle account conflicts correctly, ensure the following:
login in the "sign-in prompt": Do not set the sign-in prompt including the login in it. If set incorrectly, Logto will automatically sign in the account associated with the magic link token, bypassing the account switch prompt.signIn() function, specify the clearTokens: false parameter to prevent clearing existing tokens. If this option is used, ensure you manually clear tokens in the sign-in callback page.After proper configuration, the user experience will be as follows:

When users click on an invalid magic link, they will be redirected to an error page with a clear explanation of the issue. Below are the possible error scenarios and their messages:
| Name | Description |
|---|---|
| token_not_found | Active token not found with given email and token. |
| email_mismatch | Email mismatch with given token. |
| token_expired | The token is expired. |
| token_consumed | The token has been consumed. |
| token_revoked | The token has been revoked. |
| cannot_reactivate_token | Cannot reactivate the token. |
Each error page will provide a specific message, helping users understand the reason behind the invalid magic link and guiding them on the next steps. For example:

Logto delivers enterprise-level security through flexible, passwordless sign-in flows using magic links. It's a simple but powerful way to create smooth user experiences—whether you're inviting users to join an organization, letting them create accounts effortlessly, or providing hassle-free authentication. And because Logto handles tricky situations like account conflicts and expired tokens, your users get a secure, frustration-free process every time.
Ready to modernize your IAM with bulletproof authentication?