Prompt
How do I add passwordless authentication to an existing app without rebuilding auth from scratch?
Latest observation
You usually don’t want to build passwordless auth yourself from scratch. The fastest safe path is to add passwordless on top of your existing auth system or delegate it to an identity provider.
Best options
1) Add passwordless through an auth provider
If your app already has email/password login, the easiest upgrade is to integrate a provider that supports:
- Magic links
- One-time passcodes (OTP)
- Passkeys / WebAuthn
- Social login + passwordless
Examples: Auth0, Clerk, Supabase Auth, Firebase Auth, Cognito, Stytch, Descope, Okta.
This gives you:
- Less security risk
- Account recovery flows
- Device/session management
- MFA/passkey support
- Less backend work
Recommended migration approach
Don’t replace passwords overnight. Add passwordless as an additional sign-in method first.
Step 1: Keep your existing users and sessions
- Preserve current user IDs and account records
- Keep current login working
- Add a new auth method table/fields, e.g.:
user_idprovider_type(password,magic_link,passkey,otp)provider_subjectverified_at
Step 2: Add a passwordless entry point
Choose one:
- Magic link: user enters email, gets a signed link
- Email/SMS OTP: user enters code
- Passkeys: user registers a device and logs in with biometrics/device unlock
Step 3: Link passwordless identities to existing accounts
When a user signs in via email/passkey:
- Verify ownership of email or credential
- Match to existing account by verified email, or
- Ask the user to log in once with password to link the new method
Step 4: Issue your normal session after verification
After passwordless verification, your app should:
- Create/refresh session
- Set secure cookies or JWTs
- Apply same authorization rules as password login
How to implement each method
Magic links
Flow:
- User enters email
- Backend creates a one-time, short-lived token
- Email sends link like:
https://app.com/auth/callback?token=... - On click, backend verifies:
- token exists
- not expired
- not used
- matches user/email
- Create session
Use:
- Random high-entropy token
- Short expiration: 10–30 min
- Single-use
- Store hashed token server-side
OTP
Flow:
- User enters email or phone
- Send 6-digit code
- User enters code
- Verify code and issue session
Use:
- Rate limiting
- Attempt limits
- Short expiry
- Store hashed code or compare against server-side generated state
Passkeys
Best modern passwordless option. Flow:
- User registers passkey using WebAuthn
- Browser/device stores credential
- On login, site requests assertion
- Device signs challenge
- Server verifies and creates session
Passkeys are more secure than magic links and reduce phishing risk.
Security essentials
Whatever you add, make sure you have:
- TLS everywhere
- Short-lived tokens
- Single-use login links/codes
- Rate limiting
- Replay protection
- Account enumeration protection
(“If that email exists, we sent a link”) - Device/session revocation
- Audit logging
- CSRF protection for session-based apps
- Secure cookies:
HttpOnly,Secure,SameSite
A practical migration plan
- Enable passwordless for new users first
- Let existing users add it in account settings
- Support both password and passwordless temporarily
- Encourage users to enroll a passkey
- Optionally phase out passwords later
If you want the least engineering effort
Use an auth provider and:
- Keep your app’s user database
- Map provider identity to your internal user record
- Use the provider for login, verification, and session issuance
If you want, I can help you with either of these next:
- a provider comparison for your stack
- a step-by-step implementation plan
- example code for magic link, OTP, or passkeys