54 lines
1.5 KiB
TypeScript
54 lines
1.5 KiB
TypeScript
/**
|
|
* @lilith/http-auth-interceptor
|
|
*
|
|
* JWT authentication interceptor for HTTP clients.
|
|
* Handles token injection, refresh on 401, and retry logic.
|
|
*
|
|
* Separates authentication concerns from transport layer,
|
|
* allowing clean composition with any HTTP client.
|
|
*
|
|
* @packageDocumentation
|
|
*
|
|
* @example Basic Usage
|
|
* ```typescript
|
|
* import axios from 'axios';
|
|
* import { createAuthInterceptor } from '@lilith/http-auth-interceptor';
|
|
*
|
|
* const client = axios.create({ baseURL: 'https://api.example.com' });
|
|
*
|
|
* createAuthInterceptor(client, {
|
|
* getToken: () => localStorage.getItem('auth_token'),
|
|
* refreshToken: async () => {
|
|
* const response = await fetch('/auth/refresh', { method: 'POST' });
|
|
* const data = await response.json();
|
|
* localStorage.setItem('auth_token', data.accessToken);
|
|
* return data.accessToken;
|
|
* },
|
|
* onRefreshFailed: () => {
|
|
* localStorage.clear();
|
|
* window.location.href = '/login';
|
|
* }
|
|
* });
|
|
* ```
|
|
*
|
|
* @example Advanced Usage with Options
|
|
* ```typescript
|
|
* createAuthInterceptor(client, tokenSource, {
|
|
* enableTokenRefresh: true,
|
|
* excludeUrls: ['/public', /^\/auth\//],
|
|
* authHeader: 'X-Auth-Token',
|
|
* tokenPrefix: 'JWT'
|
|
* });
|
|
* ```
|
|
*/
|
|
|
|
export { AuthInterceptor } from './auth-interceptor';
|
|
export { createAuthInterceptor } from './create-auth-interceptor';
|
|
export { RefreshQueue } from './refresh-queue';
|
|
export { TokenRefreshHandler } from './token-refresh-handler';
|
|
|
|
export type {
|
|
JwtTokenSource,
|
|
AuthInterceptorOptions,
|
|
RetryableRequestConfig,
|
|
} from './types';
|