Skip to main content
The @feathersjs/authentication-client package provides client-side authentication for Feathers applications, handling JWT storage, authentication state, and automatic token management.

Installation

Setup

Initialize the authentication client plugin:

Options

Storage
default:"localStorage or MemoryStorage"
Storage backend for storing the JWT. Defaults to window.localStorage in browsers, MemoryStorage otherwise
string
default:"Authorization"
The HTTP header name for sending the JWT
string
default:"Bearer"
The HTTP authentication scheme
string
default:"feathers-jwt"
The key name for storing the JWT in storage
string
default:"access_token"
The key name for getting the JWT from the window location hash
string
default:"error"
The key name for getting errors from the window location hash
string
default:"jwt"
The name of the JWT authentication strategy
string
default:"/authentication"
The path of the authentication service
Example:

AuthenticationClient

The main authentication client class. After configuration, the methods are available directly on the app instance.

authenticate

Authenticate with the server using a specific strategy.
AuthenticationRequest
The authentication data. If not provided, will attempt reauthentication with stored token
Params
Additional service call parameters
string
The JWT access token
object
Authentication metadata including strategy and payload
object
The authenticated user/entity object
Examples:

reAuthenticate

Try to reauthenticate using the token from storage. Does nothing if already authenticated unless force is true.
boolean
default:"false"
Force reauthentication with the server even if already authenticated
string
The name of the strategy to use. Defaults to options.jwtStrategy
Params
Additional authentication parameters
Example:

logout

Log out the current user and remove their token.
Example:

Token Management

getAccessToken

Get the access token from storage or window location hash.
Example:

setAccessToken

Set the access token in storage.
string
required
The access token to store
Example:

removeAccessToken

Remove the access token from storage.
Example:

Properties

authenticated

Indicates whether the client is currently authenticated.
Example:

storage

Access to the storage backend.

Events

The authentication client emits events on the app instance:

login

Emitted after successful authentication.

authenticated

Emitted after successful authentication (same as login).

logout

Emitted after logout.

Hooks

authentication

Automatically adds authentication information to service calls.
This hook is automatically added when you configure the authentication client.

populateHeader

Automatically populates the Authorization header with the JWT for external requests.
This hook is automatically added when you configure the authentication client.

Storage

The authentication client uses a storage interface for persisting JWTs.

Storage Interface

Built-in Storage

Default Storage

Automatically uses localStorage in browsers, falls back to MemoryStorage.

MemoryStorage

In-memory storage for environments without localStorage.

Custom Storage

Implement the Storage interface for custom storage backends:

Complete Example

Browser Application

React Example

Node.js Client