Skip to main content

Overview

Magic Link provides a passwordless sign-in experience. Users enter their email, receive a link, and click it to authenticate — no password needed.

Benefits

  • No password required — one-click authentication
  • Auto sign-up — new users are created automatically
  • Secure — links expire in 5 minutes and are one-time use
  • Uses existing infrastructure — same Nodemailer + Gmail SMTP setup

How It Works

1

User enters email

On the sign-in page, the user provides their email address.
2

Server generates a magic link

Better Auth creates a secure token (32 characters), stores it in the verification collection, and triggers the email callback.
3

Email is sent

In production, a styled email with the magic link is sent. In development, the link is logged to the console.
4

User clicks the link

The link hits /api/auth/magic-link/verify?token=..., Better Auth validates the token, creates a session, and redirects to the dashboard.

Server Configuration

The magic link plugin is configured in lib/better-auth/auth.ts:

Client Usage

Testing

  1. Run npm run dev
  2. Go to the sign-in page and enter an email
  3. Check the terminal for the magic link URL:
  1. Copy the URL and paste it in your browser

Customization

Security

  • 5-minute expiry — links become invalid quickly
  • One-time use — each link can only be used once
  • Cryptographic tokens — 32-character secure random strings
  • HTTPS only in production
  • Auto-verified — users are marked as emailVerified: true