Skip to main content
The magic link plugin lets users sign in without a password. When a user enters their email, Better Auth emails them a link. Clicking the link authenticates them and creates a session.

Installation

1

Add the server plugin

Import and configure magicLink in your auth config. You must provide a sendMagicLink function that delivers the link to the user:
auth.ts
2

Add the client plugin

Add magicLinkClient to your auth client:
auth-client.ts

Usage

Call signIn.magicLink on the client with the user’s email address:
sign-in.ts
If the email address is not registered and disableSignUp is not true, the user is automatically signed up on first use.

Verification flow

When the user clicks the link:
  1. Better Auth validates the token.
  2. If valid, the user is authenticated and redirected to callbackURL.
  3. If invalid or expired, they are redirected to callbackURL?error=... (or errorCallbackURL if provided).
If no callbackURL is provided, the user is redirected to the root URL (/).

Manual verification

If you need to verify a token yourself (e.g. you built your own link format), call the magicLink.verify endpoint:
verify.ts
The function receives: A ctx context object is passed as the second argument.
auth.ts

Configuration options

Token expiry example

auth.ts