Prompt
How do I add passwordless authentication to a web app and keep the current identity stack?
Latest observation
You can add passwordless auth without replacing your current identity stack by treating it as an additional login method that eventually issues the same session/token as your existing sign-in flow.
The usual pattern
- User enters email/phone/username
- Your app checks whether that identity exists in the current user store
- If yes, you send a magic link, OTP code, or passkey challenge
- User verifies possession
- You map that verified login to the existing user account
- You create the same session/JWT/OIDC login you already use
That way, your app and downstream services still see one normalized authenticated identity.
Best approaches
1) Magic links
Best for: fastest rollout, low friction
- Send a one-time login link to the user’s email
- Include a short-lived, single-use token
- On click, validate token and sign the user in
Pros
- Easy to add
- Works with existing email-based accounts
- No new device support needed
Cons
- Depends on email security and mailbox access
- Link forwarding can be risky if not bound to device/session
Implementation tips
- Make tokens short-lived, single-use, and stored hashed
- Bind token to user, purpose, and expiry
- Optionally bind to browser session or device fingerprint
- Always invalidate after use
2) One-time passcodes (OTP)
Best for: simple UI, broader compatibility
- Email or SMS a 6-digit code
- User enters it on your site
- Verify it server-side and create the session
Pros
- Familiar UX
- Easier to reason about than links in some flows
Cons
- SMS is weaker than email/passkeys
- Code entry adds friction
- Susceptible to phishing if not paired with risk checks
Implementation tips
- Rate limit by user, IP, and device
- Limit attempts
- Use short expiry, usually 5–10 minutes
- Store OTP hashes, not plaintext
3) Passkeys / WebAuthn
Best for: strongest passwordless security
- User registers a device-bound credential
- Future logins use biometric/PIN/device unlock
- Your backend verifies WebAuthn assertions
Pros
- Strong phishing resistance
- Great user experience on supported devices
- No shared secret to steal
Cons
- More engineering complexity
- Recovery flows needed for lost devices
- Best when you can support account linking/multi-device enrollment
Implementation tips
- Support discoverable credentials if possible
- Keep fallback login methods for recovery
- Store credential IDs and public keys in your existing user record or auth profile table
How to keep the current identity stack
Keep your current user directory
Don’t create a second user database. Instead:
- Keep your current
userstable / IdP / directory - Add a new table or fields for passwordless factors, such as:
magic_link_tokensotp_challengeswebauthn_credentialsverified_emailverified_phone
Keep your existing session layer
After passwordless verification:
- Issue the same session cookie, access token, or OIDC session you already use
- Preserve existing claims/roles/groups from the current identity source
Keep account linking logic
If users can already sign in with passwords, SSO, or social login:
- Match the passwordless factor to the same canonical user
- Use verified email/phone as linking signals only if they’re already trusted
- Prefer explicit linking for high-risk accounts
Keep policy and authorization unchanged
Your authorization should continue to rely on:
- Current roles
- Groups
- Tenant/org membership
- Risk/assurance level if needed
Passwordless should only change how identity is proven, not how access is decided.
Recommended architecture
If you use your own auth service
Add a passwordless module that handles:
- Enrollment
- Challenge creation
- Challenge verification
- Session issuance
If you use an external IdP
Use an IdP that supports passwordless and federation:
- Configure passwordless as an MFA or primary factor
- Federate your app via OIDC/SAML
- Keep app authorization as-is
This is often the easiest way to preserve the current stack.
Migration strategy
-
Start with one passwordless option
Usually magic link or email OTP. -
Allow it alongside passwords Don’t force migration on day one.
-
Collect telemetry Measure:
- Login success rate
- Time to sign in
- Support tickets
- Abandonment by device/browser
-
Gradually promote passwordless Encourage it for new users and trusted returning users.
-
Add passkeys later Use them as the preferred method for stronger security.
Security checklist
- Short-lived, single-use challenges
- Rate limiting and abuse detection
- Anti-replay protection
- Device/session binding where practical
- Secure token storage and hashing
- Clear recovery flows
- Audit logs for login events
- Step-up auth for sensitive actions
- Email/phone change re-verification
- Phishing-resistant methods preferred where possible
Simple flow example
Existing password login today
- User submits email + password
- Backend verifies password
- Session cookie issued
Add passwordless
- User submits email
- Backend creates magic link token
- User clicks link
- Backend verifies token
- Same session cookie issued
- User lands in app with same roles/claims
No downstream code needs to change if it already trusts the session.
Best practical recommendation
If you want the least disruption:
- Use magic links or email OTP first
- Keep your current identity store and sessions
- Add passkeys as the preferred long-term method
- Preserve the same user IDs and authorization model
If you want, I can also sketch:
- a reference architecture,
- a database schema, or
- an implementation example for Auth0 / Okta / Azure AD / Keycloak / custom Node/React app.