Magic Links
Learn how to authenticate or verify users with magic links.
Overview
Clerk supports passwordless authentication with magic links, which lets users sign in and sign up without having to remember a password. During login or registration, users will be asked to enter their email address to receive an email message with a link that can be clicked and complete the authentication process.
This one-click, link based verification method is often referred to as a "magic link". The process is similar to sending a one-time code to your users, but skipping the part where they have to come back to your app and enter the code. This is where the "magic" kicks in.
As a form of passwordless authentication, magic links arguably provide greater security and a better user experience than traditional passwords. Since there's less steps involved in every authentication attempt, the user experience is better than one-time codes. However, magic links are not without their downsides, and often still boil down to the email providers "knowledge based factor" instead of yours.
Magic links are the default passwordless authentication strategy when using Clerk. They can be used to sign up new users, sign in existing ones or allow existing users to verify newly entered email addresses to their profile.
Your users will still be able to choose an alternative authentication (or verification) method even after they've clicked the magic link they received in their inbox. Magic links are simply the default authentication method for email address based, passwordless authentication in Clerk.
Looking for one-time code (OTP) authentication? Check out our One-time code authentication guide.
Magic link flow
Magic links can be used to easily authenticate users or verify their email addresses. In all the above cases, Clerk will take care of the plumbing and allow you to offer a seamless experience to your users:
- User enters their email address and asks for a magic link.
- Your application waits for the verification result.
- Clerk sends an email to the user, containing a link to the verification URL.
- User clicks the magic link. This can happen on the same device where they entered their email address, or a different device.
- Clerk will verify the user's identity and advance any sign in or sign up attempt that might be in progress. In case the verification fails, Clerk will inform the user.
- Your user will now be logged in on the device or tab that they opened the link.
Magic links work on any device. There's no constraint on where the link will be opened. For example, a user might try to sign in from their desktop browser, but open the link from their mobile phone.
As an additional security measure, we expire magic links after a while. This way we can guard against cases where a stale link might be compromised. From a user experience perspective, the magic link flow is supposed to be nearly synchronous. Don't worry, your users will have plenty of time to complete the flow before the magic link expires.
Clerk provides a highly flexible API that allows you to hook into any of the above steps, while abstracting away all the complexities of a magic link based authentication or verification flow.
We take care of the boring stuff, like efficient polling, secure session management and different device authentication so you can focus on your application code.
Before you start
- You need to create a Clerk Application in your Clerk Dashboard. For more information, check out our Set up your application guide.
- You need to install Clerk React or ClerkJS to your application.
Configuration
Magic link authentication can be configured through the Clerk Dashboard. Go to your instance, then User & Authentication > Email, Phone, Username. Simply choose Email verification link as the authentication factor.

Don't forget that you also need to make sure you've configured your application instance to request the user's email address. Users can receive magic links only via email messages. Make sure you toggle Email address on under the Contact information section. You can verify that email addresses will be used for identification, by clicking on the cog next to the Email address option and switching on the Used for identification toggle in the modal.

Don't forget to click on the Apply Changes button at the bottom of the page once you're done configuring your instance.
That's all you need to do to enable authentication with magic links for your instance. Now let's see how we can make some magic with our configuration.
Using Clerk Hosted Pages
If you're looking for the fastest way to implement authentication with magic links, you can leverage Clerk Hosted Pages for your sign up, sign in, and user profile pages. You can set these up on your own domain, and match your website's theme with the Clerk Dashboard to create a seamless experience.
You can find your instance's sign up and sign in links in the Home section of your instance in Clerk Dashboard.

By default, the URLs for your hosted pages will match the following pattern:
https://accounts.[your-domain].com/sign-inhttps://accounts.[your-domain].com/sign-uphttps://accounts.[your-domain].com/user
For development instances, Clerk will issue you a domain on "lcl.dev". In production, you'll need to supply your own domain. See Production setup or more information.
Clerk provides SDKs to make navigating to these pages easy.
1import {2RedirectToSignUp,3RedirectToSignIn4} from "@clerk/clerk-react";56// Rendering the RedirectToSignOut component will7// cause the browser to navigate to the Sign up8// URL and show the Sign Up Clerk Hosted Page.9function App() {10return <RedirectToSignUp />;11}1213// Rendering the RedirectToSignIn component will14// cause the browser to navigate to the Sign in15// URL and show the Sign In Clerk Hosted Page.16function App() {17return <RedirectToSignIn />;18}
Read our detailed Clerk Hosted Pages guide to learn more.
Using Clerk Components
You can leverage Clerk Components in order to easily add support for magic link based authentication in your application.
Clerk provides a <SignUp /> pre-built component that renders a sign up form to handle user registrations.
Similarly, there's a <SignIn /> pre-built component that renders a sign in form and takes care of user authentication and session creation.
On the other hand for adding and verifying email addresses to a user's profile, Clerk offers a customizable <UserProfile /> pre-built component.
Note that you don't need to pass any special options to the pre-built <SignUp />,<SignIn /> and <UserProfile /> components. Magic link authentication/verification will just work, since you already configured it through the Clerk dashboard.
Sign up using Clerk components
Signing users up to your application is as simple as rendering the <SignUp /> component.
1import { SignUp } from "@clerk/nextjs";23// SignUpPage is your custom sign up page component.4function SignUpPage() {5return (6// The Clerk SignUp component needs no special7// configuration. Passwordless authentication8// will just work when configured from the9// Clerk dashboard.10<SignUp />11);
Sign in using Clerk components
Signing users in with a magic link is as simple as mounting the <SignIn /> component.
1import { SignIn } from "@clerk/nextjs";23// SignInPage is your custom sign in page component.4function SignInPage() {5return (6// The Clerk SignIn component needs no special7// configuration.8<SignIn />9);10}
Email address verification using Clerk components
Users can add email addresses through their profile pages and they will be verified via magic links. Simply render the <UserProfile /> component.
1import { UserProfile } from "@clerk/nextjs";23// Profile is your custom user profile page component.4function Profile() {5return (6// The Clerk UserProfile component needs no special7// configuration.8<UserProfile />9);10}
If you're interested in more pre-built offerings, you can read more about Clerk Components.
Custom flow
In case one of the above integration methods doesn't cover your needs, you can make use of lower level commands and create a completely custom magic link authentication flow.
You still need to configure your instance in order to enable magic link authentication, as described at the top of this guide.
Sign up using custom flow
Registration with magic links follows a set of steps that require users to enter their email address as authentication identifiers and click on a link that's delivered to them via email message.
The sign up process can be completed on the same or a different device. For example, users might enter their email address in their desktop browser, but click the sign up magic link from their mobile phone. The user's email address will still be verified and registration will proceed.
Let's see all the steps involved in more detail.
- Initiate the sign up process, by collecting the user's identifier. It must be their email address.
- Start the magic link verification flow. There's two parts to the flow:
- Prepare a verification for the email address by sending an email with a magic link to the user.
- Wait until the magic link is clicked. This is a polling behavior which can be cancelled at any time.
- Handle the magic link verification result accordingly. Note that the magic link can be clicked on a different device/browser than the one which initiated the flow.
- The verification was successful so you need to continue with the sign up flow.
- The verification failed or the magic link has expired.
Clerk provides a highly flexible API that allows you to hook into any of the above steps, while abstracting away all the complexities of a magic link based sign up flow.
1import React from "react";2import { useRouter } from "next/router";3import {4MagicLinkErrorCode,5isMagicLinkError,6useClerk,7useSignUp8} from "@clerk/nextjs";910// pages/sign-up.jsx11// Render the sign up form.12// Collect user's email address and send a magic link with which13// they can sign up.14function SignUp() {15const [emailAddress, setEmailAddress] = React.useState("");16const [expired, setExpired] = React.useState(false);17const [verified, setVerified] = React.useState(false);18const router = useRouter();19const { signUp, setSession } = useSignUp();2021const { startMagicLinkFlow, cancelMagicLinkFlow } =22signUp.createMagicLinkFlow();2324async function submit(e) {25e.preventDefault();26setExpired(false);27setVerified(false);2829// Start the sign up flow, by collecting30// the user's email address.31await signUp.create({ emailAddress });3233// Start the magic link flow.34// Pass your app URL that users will be navigated35// when they click the magic link from their36// email inbox.37// su will hold the updated sign up object.38const su = await startMagicLinkFlow({39redirectUrl: "https://your-app.domain.com/verification",40});4142// Check the verification result.43const verification = su.verifications.emailAddress;44if (verification.verifiedFromTheSameClient()) {45setVerified(true);46// If you're handling the verification result from47// another route/component, you should return here.48// See the <MagicLinkVerification/> component as an49// example below.50// If you want to complete the flow on this tab,51// don't return. Check the sign up status instead.52return;53} else if (verification.status === "expired") {54setExpired(true);55}5657if (su.status === "complete") {58// Sign up is complete, we have a session.59// Navigate to the after sign up URL.60setSession(61su.createdSessionId,62() => router.push("/after-sign-up-path"),63);64return;65}66}6768if (expired) {69return (70<div>Magic link has expired</div>71);72}7374if (verified) {75return (76<div>Signed in on other tab</div>77);78}7980return (81<form onSubmit={submit}>82<input83type="email"84value={emailAddress}85onChange={e => setEmailAddress(e.target.value)}86/>87<button type="submit">88Sign up with magic link89</button>90</form>91);92}9394// pages/verification.jsx95// Handle magic link verification results. This is96// the final step in the magic link flow.97function Verification() {98const [99verificationStatus,100setVerificationStatus,101] = React.useState("loading");102103const { handleMagicLinkVerification } = useClerk();104105React.useEffect(() => {106async function verify() {107try {108await handleMagicLinkVerification({109redirectUrl: "https://redirect-to-pending-sign-up",110redirectUrlComplete: "https://redirect-when-sign-up-complete",111});112// If we're not redirected at this point, it means113// that the flow has completed on another device.114setVerificationStatus("verified");115} catch (err) {116// Verification has failed.117let status = "failed";118if (isMagicLinkError(err) && err.code === MagicLinkErrorCode.Expired) {119status = "expired";120}121setVerificationStatus(status);122}123}124verify();125}, []);126127if (verificationStatus === "loading") {128return <div>Loading...</div>129}130131if (verificationStatus === "failed") {132return (133<div>Magic link verification failed</div>134);135}136137if (verificationStatus === "expired") {138return (139<div>Magic link expired</div>140);141}142143return (144<div>145Successfully signed up. Return to the original tab to continue.146</div>147);148}
Sign in using custom flow
Signing users in your application is probably the most popular use-case for magic links. Users enter their email address and then click on a link that's delivered to them via email message in order to log in.
The sign in process can be completed on the same or a different device. For example, users might enter their email address in their desktop browser, but click the sign in magic link from their mobile phone. The user's email address will still be verified and authentication will proceed.
Let's see all the steps involved in more detail.
- Initiate the sign in process, by collecting the user's authentication identifier. It must be their email address.
- Start the magic link verification flow. There's two parts to the flow:
- Prepare a verification for the email address by sending an email with a magic link to the user.
- Wait until the magic link is clicked. This is a polling behavior which can be cancelled at any time.
- Handle the magic link verification result accordingly. Note that the magic link can be clicked on a different device/browser than the one which initiated the flow.
- The verification was successful so you need to continue with the sign in flow.
- The verification failed or the magic link has expired.
Clerk provides a highly flexible API that allows you to hook into any of the above steps, while abstracting away all the complexities of a magic link based sign in flow.
1import React from "react";2import { useRouter } from "next/router";3import {4MagicLinkErrorCode,5isMagicLinkError,6useClerk,7useSignIn,8} from "@clerk/nextjs";910// pages/sign-in.jsx11// Render the sign in form.12// Collect user's email address and send a magic link with which13// they can sign in.14function SignIn() {15const [emailAddress, setEmailAddress] = React.useState("");16const [expired, setExpired] = React.useState(false);17const [verified, setVerified] = React.useState(false);18const router = useRouter();19const { signIn, setSession } = useSignIn();2021const { startMagicLinkFlow, cancelMagicLinkFlow } = signUp.createMagicLinkFlow();2223async function submit(e) {24e.preventDefault();25setExpired(false);26setVerified(false);2728// Start the sign in flow, by collecting29// the user's email address.30const si = await signIn.create({ identifier: emailAddress });31const { emailAddressId } = si.supportedFirstFactors.find(32ff => ff.strategy === "email_link" && ff.safeIdentifier === emailAddress33);3435// Start the magic link flow.36// Pass your app URL that users will be navigated37// res will hold the updated sign in object.38const res = await startMagicLinkFlow({39emailAddressId: email_address_id,40redirectUrl: "https://your-app.domain.com/verification",41});4243// Check the verification result.44const verification = res.firstFactorVerification;45if (verification.verifiedFromTheSameClient()) {46setVerified(true);47// If you're handling the verification result from48// another route/component, you should return here.49// See the <Verification/> component as an50// example below.51// If you want to complete the flow on this tab,52// don't return. Simply check the sign in status.53return;54} else if (verification.status === "expired") {55setExpired(true);56}57if (res.status === "complete") {58// Sign in is complete, we have a session.59// Navigate to the after sign in URL.60setSession(61res.createdSessionId,62() => router.push("/after-sign-in-path"),63);64return;65}66}6768if (expired) {69return (70<div>Magic link has expired</div>71);72}7374if (verified) {75return (76<div>Signed in on other tab</div>77);78}7980return (81<form onSubmit={submit}>82<input83type="email"84value={emailAddress}85onChange={e => setEmailAddress(e.target.value)}86/>87<button type="submit">88Sign in with magic link89</button>90</form>91);92}9394// pages/verification.jsx95// Handle magic link verification results. This is96// the final step in the magic link flow.97function Verification() {98const [99verificationStatus,100setVerificationStatus,101] = React.useState("loading");102103const { handleMagicLinkVerification } = useClerk();104105React.useEffect(() => {106async function verify() {107try {108await handleMagicLinkVerification({109redirectUrl: "https://redirect-to-pending-sign-in-like-2fa",110redirectUrlComplete: "https://redirect-when-sign-in-complete",111});112// If we're not redirected at this point, it means113// that the flow has completed on another device.114setVerificationStatus("verified");115} catch (err) {116// Verification has failed.117let status = "failed";118if (isMagicLinkError(err) && err.code === MagicLinkErrorCode.Expired) {119status = "expired";120}121setVerificationStatus(status);122}123}124verify();125}, []);126127if (verificationStatus === "loading") {128return <div>Loading...</div>129}130131if (verificationStatus === "failed") {132return (133<div>Magic link verification failed</div>134);135}136137if (verificationStatus === "expired") {138return (139<div>Magic link expired</div>140);141}142143return (144<div>145Successfully signed in. Return to the original tab to continue.146</div>147);148}
Email address verification
Magic links can also provide a nice user experience for verifying email addresses that users add through when updating their profile. The flow is similar to one-time code verification, but users need only click on the magic link; there's no need to return to your app.
- Collect the user's email address.
- Start the magic link verification flow. There's two parts to the flow:
- Prepare a verification for the email address by sending an email with a magic link to the user.
- Wait until the magic link is clicked. This is a polling behavior which can be cancelled at any time.
- Handle the magic link verification result accordingly. Note that the magic link can be clicked on a different device/browser than the one which initiated the flow.
- The verification was successful.
- The verification failed or the magic link has expired.
Clerk provides a highly flexible API that allows you to hook into any of the above steps, while abstracting away all the complexities of a magic link based email address verification.
1import React from "react";2import { useUser, useMagicLink } from "@clerk/nextjs";34// A page where users can add a new email address.5function NewEmailPage() {6const [email, setEmail] = React.useState('');7const [emailAddress, setEmailAddress] = React.useState(null);8const [verified, setVerified] = React.useState(false);910const user = useUser();1112async function submit(e) {13e.preventDefault();14const res = await user.createEmailAddress({ email });15setEmailAddress(res);16}1718if (emailAddress && !verified) {19return (20<VerifyWithMagicLink21emailAddress={emailAddress}22onVerify={() => setVerified(true)}23/>24);25}2627return (28<form onSubmit={submit}>29<input30type="email"31value={email}32onChange={e => setEmail(e.target.value)}33/>34</form>35);36}3738// A page which verifies email addresses with magic links.39function VerifyWithMagicLink({40emailAddress,41onVerify,42}) {43const { startMagicLinkFlow } = useMagicLink(emailAddress);4445React.useEffect(() => {46verify();47}, []);4849async function verify() {50// Start the magic link flow.51// Pass your app URL that users will be navigated52// when they click the magic link from their53// email inbox.54const res = await startMagicLinkFlow({55redirectUrl: "https://redirect-from-email-magic-link",56});5758// res will hold the updated EmailAddress object.59if (res.verification.status === "verified") {60onVerify();61} else {62// act accordingly63}64}6566return (67<div>68Waiting for verification...69</div>70);71}