@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 otherwisestring
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
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
reAuthenticate
Try to reauthenticate using the token from storage. Does nothing if already authenticated unlessforce 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.jwtStrategyParams
Additional authentication parameters
logout
Log out the current user and remove their token.Token Management
getAccessToken
Get the access token from storage or window location hash.setAccessToken
Set the access token in storage.string
required
The access token to store
removeAccessToken
Remove the access token from storage.Properties
authenticated
Indicates whether the client is currently authenticated.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.populateHeader
Automatically populates the Authorization header with the JWT for external requests.Storage
The authentication client uses a storage interface for persisting JWTs.Storage Interface
Built-in Storage
Default Storage
Automatically useslocalStorage in browsers, falls back to MemoryStorage.