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
Server generates a magic link
Better Auth creates a secure token (32 characters), stores it in the
verification collection, and triggers the email callback.Email is sent
In production, a styled email with the magic link is sent. In development, the link is logged to the console.
Server Configuration
The magic link plugin is configured inlib/better-auth/auth.ts:
Client Usage
Testing
- Development
- Production
- Run
npm run dev - Go to the sign-in page and enter an email
- Check the terminal for the magic link URL:
- Copy the URL and paste it in your browser
Customization
Change expiry time
Change expiry time
Disable auto sign-up
Disable auto sign-up
Store tokens as hashed
Store tokens as hashed
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