How It Works
The Local strategy:- Accepts login credentials (username/email and password)
- Queries the user database by username field
- Compares the provided password with the stored bcrypt hash
- Returns the authenticated user entity
- Creates a JWT access token (via authentication service)
Installation
Setup
1
Install Dependencies
The local strategy requires the base authentication package:
2
Configure Local Strategy
Add local strategy configuration:
3
Register Strategy
Register the local strategy with your authentication service:
4
Hash Passwords
Set up password hashing for user creation and updates:
Configuration Options
Required Options
Optional Options
Basic Usage
Client Login
Different Field Names
Password Hashing
Using Schema Resolvers (Recommended)
The modern approach uses Feathers schema resolvers:Using Legacy Hook (Deprecated)
Manual Password Hashing
BCrypt Configuration
ThehashSize option controls bcrypt complexity:
10rounds: ~100ms (default, good for most apps)12rounds: ~400ms (more secure)14rounds: ~1600ms (very secure, may impact UX)
Protecting Password Fields
Using Schema Dispatch Resolvers (Recommended)
Using Legacy Hook (Deprecated)
Custom Validation
Custom Field Mapping
Map different field names between request and database:Custom Query
Customize the database query:Custom Password Comparison
Security Best Practices
Password Requirements
Validate password strength on user creation:Generic Error Messages
Rate Limiting
Implement rate limiting to prevent brute force attacks:Account Lockout
Lock accounts after repeated failed attempts:Password History
Prevent password reuse:Common Patterns
Email/Username Login
Support both email and username:Multi-Tenancy
Scope authentication to tenants:Two-Factor Authentication
Troubleshooting
Invalid Login Error
Password Not Hashing
Configuration Errors
Next Steps
JWT Strategy
Understand JWT token authentication
OAuth Strategy
Add social login with OAuth providers