Skip to main content
The Local authentication strategy provides traditional username and password authentication for Feathers applications. It uses bcrypt for secure password hashing and supports customizable field names and validation.

How It Works

The Local strategy:
  1. Accepts login credentials (username/email and password)
  2. Queries the user database by username field
  3. Compares the provided password with the stored bcrypt hash
  4. Returns the authenticated user entity
  5. 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

The modern approach uses Feathers schema resolvers:

Using Legacy Hook (Deprecated)

The hashPassword hook is deprecated. Use schema resolvers instead.

Manual Password Hashing

BCrypt Configuration

The hashSize option controls bcrypt complexity:
BCrypt rounds comparison:
  • 10 rounds: ~100ms (default, good for most apps)
  • 12 rounds: ~400ms (more secure)
  • 14 rounds: ~1600ms (very secure, may impact UX)

Protecting Password Fields

Using Legacy Hook (Deprecated)

The protect hook is deprecated. Use schema dispatch resolvers instead.

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

Never reveal whether a username exists in error messages. This prevents user enumeration attacks.

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