AuthServiceFactory
Cosa fa
AuthServiceFactory applica il Factory Pattern per centralizzare la creazione di istanze AuthService. Mantiene lo stesso stile dichiarativo delle altre factory del package (AuthStrategyFactory, CacheStrategyFactory, HttpClientFactory), facilitando refactoring e testing.
API
class AuthServiceFactory {
static create(httpClient: IHttpClient, authStrategy: IAuthStrategy): IAuthService
}
create(httpClient, authStrategy)
| Parametro | Tipo | Descrizione |
|---|---|---|
httpClient | IHttpClient | Client HTTP per le richieste a /auth/* |
authStrategy | IAuthStrategy | Strategia di persistenza token |
Ritorna un'istanza che implementa IAuthService (e internamente anche IAuthHandler).
Esempio
import {
HttpClientFactory,
AuthStrategyFactory,
AuthServiceFactory,
} from '@pzeta/postgrest'
const httpClient = HttpClientFactory.createFetchClient()
const strategy = AuthStrategyFactory.createJwtStrategy()
const authService = AuthServiceFactory.create(httpClient, strategy)
// Collega l'handler per retry automatico su 401
httpClient.setAuthHandler(authService)
await authService.login({ email, password })
Quando usarla
Sempre, in luogo di new AuthService(...) diretto. Mantiene il codice client uniforme con le altre parti del package e isola eventuali parametri opzionali futuri (es. logger) dietro al contratto della factory.
Vedi anche
AuthService— implementazione concretaAuthStrategyFactory— factory per le strategy
AuthService
Servizio di autenticazione completo. Login, logout, register, activate, forgotPassword, resetPassword, refresh con locking concorrente. Implementa anche IAuthHandler per retry automatico su 401.
AuthStrategyFactory
Factory statica per la creazione di tutte le strategie di autenticazione (JWT, Cookie, ApiKey, NoAuth). Espone metodi specifici e un metodo dinamico create(type, options).