Prompt
email OTP sign in
Latest observation
Nov 18, 2026
OpenAI APIWeb search: off
If you want to implement email OTP sign-in (one-time passcode / magic code by email), the typical flow is:
- User enters email
- Backend generates a short-lived OTP
- Send OTP to the email
- User enters OTP
- Backend verifies it
- If valid, create a session / JWT and sign the user in
Common implementation options
Option 1: Numeric OTP code
- Example:
482913 - User types the code into a form
- Good for simple UX and direct verification
Option 2: Magic link
- Email contains a link with a token
- User clicks link to sign in
- Often easier on mobile and more user-friendly
Security recommendations
- OTP should expire quickly: 5–10 minutes
- Store only a hashed version of the OTP
- Limit retries: e.g. 5 attempts
- Rate-limit requests per email/IP
- Invalidate OTP after successful use
- Use HTTPS only
Example backend flow
POST /auth/request-otp- input: email
- action: generate OTP and email it
POST /auth/verify-otp- input: email + otp
- action: verify and issue session/JWT
Example request payloads
Request OTP
{
"email": "user@example.com"
}
Verify OTP
{
"email": "user@example.com",
"otp": "482913"
}
Example UX copy
- “Enter your email to receive a sign-in code”
- “We sent a 6-digit code to your email”
- “Code expires in 10 minutes”
If you want, I can also provide:
- a full backend example in Node.js / Python / Go
- a frontend form flow
- or an implementation using NextAuth / Firebase / Supabase