Prompt
How do I let users sign in with email magic links instead of passwords?
Latest observation
Oct 28, 2026
OpenAI APIWeb search: off
To let users sign in with email magic links instead of passwords, you typically implement a passwordless authentication flow:
Basic flow
- User enters their email address.
- Your backend generates a single-use, time-limited token.
- You email the user a link like:
https://yourapp.com/auth/verify?token=... - When they click it, your backend:
- verifies the token
- checks it hasn’t expired or been used
- logs the user in
- Create a session cookie or issue a JWT after verification.
Important security rules
- Token must expire quickly: usually 10–30 minutes.
- Single use only: invalidate after first successful login.
- Store token hashed in the database, not in plaintext.
- Rate limit requests to prevent abuse/spam.
- Don’t reveal whether an email exists in your system.
- Bind the token to the email address and optionally to device/session context.
- Use HTTPS only.
Typical implementation outline
1. Request magic link
Frontend sends:
POST /auth/magic-link
{ "email": "user@example.com" }
Backend:
- normalizes email
- generates random token
- stores hashed token + expiry + email
- sends email with link
2. Verify magic link
User clicks:
GET /auth/verify?token=abc123
Backend:
- hashes received token
- looks it up in database
- verifies expiry and unused status
- marks token as used
- creates authenticated session
Data model example
A simple table might include:
idemailtoken_hashexpires_atused_atcreated_atip_address/user_agentoptional
Email example
Subject: Your sign-in link
Body:
Click this link to sign in:
https://yourapp.com/auth/verify?token=...This link expires in 15 minutes.
UX recommendations
- Show: “We sent you a sign-in link.”
- If possible, detect when the email client opens the link in a different browser and provide fallback help.
- Allow resending after a short delay.
- Consider showing a list of recent login attempts in account security settings.
If you don’t want to build it yourself
Many auth providers support this out of the box:
- Auth0
- Firebase Auth
- Clerk
- Supabase Auth
- Magic.link
- NextAuth / Auth.js (with email provider)
Example pseudocode
// request link
token = randomSecureToken()
hash = sha256(token)
saveToDb({ email, hash, expiresAt: now + 15min, usedAt: null })
sendEmail(email, `https://yourapp.com/auth/verify?token=${token}`)
// verify link
record = findByHash(sha256(token))
if (!record || record.usedAt || record.expiresAt < now) reject()
markUsed(record)
createSession(record.email)
If you want, I can also give you:
- a Node.js/Express example
- a Next.js/Auth.js setup
- a Django/Rails implementation
- or a production-ready database schema and email template