Passkeys and WebAuthn: Add Passwordless Login to Your Web App

Passkeys and WebAuthn: Add Passwordless Login to Your Web App

Passwords are the weakest part of most login systems. They get reused, phished and leaked. Passkeys replace them with public-key cryptography built on the WebAuthn standard, and they are supported across modern browsers and operating systems. I implemented WebAuthn passkeys alongside TOTP two-factor and Argon2 password hashing in a multi-tenant SaaS platform, and this post covers how the flow works and what to get right.

Key takeaways

  • A passkey is a key pair. The private key never leaves the user's device, and your server only stores the public key.
  • Passkeys are phishing-resistant because they are bound to your domain.
  • Use a maintained library on the server, and always verify the origin and relying party ID.
  • Plan account recovery before you remove passwords.

How passkeys work

WebAuthn has two ceremonies, and both follow the same shape: your server creates a random challenge, the browser asks the authenticator to sign it, and your server verifies the result.

Registration

  1. The server generates options containing a random challenge, your relying party ID (your domain) and the user's identity.
  2. The browser calls navigator.credentials.create(), and the user approves with a fingerprint, face or device PIN.
  3. The device creates a key pair and returns the public key and a credential ID.
  4. The server verifies the response and stores the credential ID, the public key and a counter.

Authentication

  1. The server generates a new challenge.
  2. The browser calls navigator.credentials.get(), and the user approves.
  3. The device signs the challenge with the private key.
  4. The server verifies the signature using the stored public key.

Why it beats passwords

  • Phishing resistance. The credential only works for the exact domain it was created on, so a look-alike site cannot use it.
  • No shared secret. There is nothing on your server that an attacker can steal and replay.
  • Better experience. One tap replaces typing and password managers.

Use a library for the server side

Verifying attestation and assertion data correctly is detailed work. Use a maintained library such as SimpleWebAuthn, which provides functions to generate registration and authentication options and to verify the responses. Check the current documentation for exact signatures, because they change between major versions.

import { generateRegistrationOptions } from "@simplewebauthn/server";

const options = await generateRegistrationOptions({
  rpName: "Example App",
  rpID: "example.com",
  userName: user.email,
  attestationType: "none",
  authenticatorSelection: { residentKey: "preferred", userVerification: "preferred" },
});
await saveChallenge(user.id, options.challenge);

Store the challenge server-side and consume it once during verification.

What to store

For each credential, save:

  • the credential ID
  • the public key
  • the signature counter
  • the transports (usb, internal, hybrid) so the browser can hint correctly
  • a label and created date so users can manage their passkeys

Common mistakes

  1. Wrong origin or RP ID. The expected origin must match exactly, including scheme and port in development.
  2. Reusing challenges. Every ceremony needs a fresh random challenge that is single-use and short-lived.
  3. No recovery path. If a user loses every device, they need a safe way back in. Offer backup codes or a verified email flow, and rate-limit it.
  4. Removing passwords too early. Roll out passkeys as an option, then make them the default once adoption is high.
  5. Skipping session hygiene. Passkeys secure login, but you still need httpOnly cookies, CSRF protection, session rotation and rate limiting.

Going further

In an enterprise setting, passkeys sit next to single sign-on. I have built per-tenant OIDC with PKCE and SCIM user sync in the same system, so organisations can choose how their users sign in. If you want modern authentication in your product, see my authentication and security service.

  • passkeys
  • WebAuthn
  • authentication
  • passwordless
  • security

Let's Work Together.

Tell me about your project. I'll reply with questions, a first approach and honest advice.