Skip to main content
The @feathersjs/authentication-local package provides local username and password authentication using bcrypt for password hashing.

Installation

LocalStrategy

Authentication strategy for username/password authentication with bcrypt password hashing.

Configuration

Configure the local strategy in your authentication settings:
string
required
The field name for the username in the authentication request (e.g., ‘email’, ‘username’)
string
required
The field name for the password in the authentication request
number
default:"10"
The bcrypt hash size (cost factor). Higher values are more secure but slower
string
The path of the entity service (inherited from main auth config)
string
The name of the entity (inherited from main auth config)
string
The entity id field (inherited from main auth config)
string
default:"Invalid login"
The error message to show when authentication fails
string
The field name in the entity for the password (defaults to passwordField). Supports dot notation
string
The field name in the entity for the username (defaults to usernameField). Supports dot notation
Example:

Setup

Register the local strategy with your authentication service:

Methods

authenticate

Authenticate a user with username and password.
AuthenticationRequest
required
The authentication request containing username and password
Params
required
Service call parameters
object
Authentication metadata with strategy name
object
The authenticated user entity
Example:

hashPassword

Hash a plain text password using bcrypt.
string
required
The plain text password to hash
Params
required
Service call parameters
Example:

comparePassword

Compare a plain text password with a hashed password.
any
required
The entity containing the hashed password
string
required
The plain text password to compare

findEntity

Find an entity by username.
string
required
The username to search for
Params
required
Service call parameters

getEntityQuery

Build the query for finding an entity. Override this to customize the query.
Query
required
The base query
Params
required
Service call parameters
Example:

Hooks

hashPassword (deprecated)

This hook is deprecated. Use the passwordHash resolver instead for better type safety and integration with Feathers schemas.
Hash a password field before saving to the database.
string
required
The field name to hash
HashPasswordOptions
Configuration options
Example:

protect (deprecated)

This hook is deprecated. Use Feathers schema dispatch resolvers for safe data representations.
Remove fields from the response to prevent exposing sensitive data.
string[]
required
Field names to remove from the response
Example:

passwordHash Resolver

The recommended way to hash passwords using Feathers schemas.
string
The authentication service name (defaults to ‘authentication’)
string
required
The local strategy name
Example:

Protecting Password Fields

Use Feathers schema dispatch resolvers to exclude password fields:

Complete Example

Server Setup

Client Usage

Custom Local Strategy

Extend LocalStrategy for custom authentication logic: