biokey-react) provides a convenient hook that wraps the JavaScript SDK with React state management.
Installation
Basic Usage
Simple Login Component
Here’s a complete React component with biometric authentication:Complete Example App
Here’s a full example with proper React patterns:Hook API Reference
useBioKey(options)
React hook that provides biometric authentication functionality.
Parameters:
options(object) - Configuration object passed toBioKeyClientrpId(string) - Your domain (defaults tolocation.hostname)rpName(string) - Display name for your appserverUrl(string | null) - Server endpoint ornullfor offline mode
Advanced Patterns
Context Provider Pattern
For app-wide authentication state:Protected Routes
Combine with React Router:Auto-login on Mount
Automatically attempt authentication when the component mounts:Custom UI States
Build custom components based on status:TypeScript Support
The hook includes TypeScript definitions:Error Handling
The hook automatically updates theerror state when operations fail:
Best Practices
- Single instance - Use the hook at the appropriate level in your component tree. For app-wide auth, use a Context Provider.
-
User feedback - Always show loading states using
isLoadingand error messages from theerrorstate. - Graceful fallback - Provide alternative authentication methods if biometric auth fails.
- Clear CTAs - Use different button text for enrollment vs authentication.
- Persist user ID - Store the user ID separately so users don’t need to re-enter it.
Next Steps
Browser SDK
Learn about the underlying JavaScript SDK
Server Setup
Set up the server for multi-device sync
Offline Mode
Build without a backend server
API Reference
Full React API documentation