Magic Links
Magic links provide passwordless authentication via email. Users enter their email address, receive a one-time link, and clicking it signs them in.How It Works
Token Generation
The backend generates a secure random token and stores it in Redis with a time-to-live (default: 10 minutes).
Verification
When the user clicks the link,
GET /api/v1/auth/magic/verify validates the token against Redis.Configuration
| Variable | Default | Description |
|---|---|---|
RESEND_API_KEY | (empty) | Resend API key for sending emails. If unset, emails are logged to stdout. |
RESEND_FROM_EMAIL | onboarding@resend.dev | Sender email address |
MAGIC_LINK_EXPIRY_MINUTES | 10 | Token expiry time in minutes |
Development Mode
WhenRESEND_API_KEY is not set, magic link emails are logged to stdout instead of sent. This makes local development easy — just check the server logs for the verification URL.
Email Setup (Production)
For production, set up a Resend account:- Sign up at resend.com
- Add and verify your sending domain
- Generate an API key
- Set
RESEND_API_KEYandRESEND_FROM_EMAILin your environment
Security
- Token format validation — tokens are validated before Redis lookup to prevent injection
- One-time use — tokens are deleted from Redis after successful verification
- Time-limited — tokens expire after the configured duration
- Email normalization — email addresses are lowercased and trimmed
- Body size cap — request body size is limited to prevent abuse
- Rate limiting — magic link requests are rate-limited (20 req/min per IP)