Skip to main content
The trusted device module lets users mark a device as trusted after completing two-factor authentication. On subsequent sign-ins from that device, 2FA is skipped. Trust is stored as an HMAC-signed fingerprint, not a plain device ID, so it cannot be guessed or forged.

Setup

lib/kavach.ts

Trust a device

After the user completes 2FA, call trust() to mark their device. Pass any stable identifier, a browser fingerprint, a cookie value you control, or a combination:
Trust after 2FA (server)

Verify a trusted device

On sign-in, check whether the device is already trusted before requiring 2FA:
Check on sign-in (server)

Revoke a device

Users can revoke specific devices from an account settings page:
Revoke one device (server)

Revoke all devices

Revoke all devices (server)

List trusted devices

List devices (server)

Configuration reference

string
required
Secret used to HMAC-sign device fingerprints. Rotate this to invalidate all trusted devices instantly.
number
default:"2592000 (30 days)"
How long a device stays trusted, in seconds.
number
default:"10"
Maximum number of trusted devices per user. Oldest is evicted when exceeded.
Last modified on April 29, 2026