import { InternalAxiosRequestConfig, AxiosInstance } from 'axios'; declare module "axios" { interface AxiosRequestConfig { skipAuthRefresh?: boolean; } } interface AuthTokens { accessToken: string; refreshToken?: string; } /** * Configuration options for the Auth Interceptor. */ interface AuthInterceptorConfig { /** * The function to call when the token expires. * Should return the new access token (and refresh token if available). */ requestRefresh: (refreshToken?: string) => Promise; /** * Function to get the current refresh token from storage. */ getRefreshToken?: () => string | null | undefined; /** Callback chạy khi refresh thành công */ onSuccess: (tokens: AuthTokens) => void; /** Callback chạy khi refresh thất bại */ onFailure: (error: any) => void; /** Tự custom cách gắn token vào header. Mặc định là 'Authorization: Bearer ...' */ attachTokenToRequest?: (request: InternalAxiosRequestConfig, token: string) => void; /** * Handler chạy trước mọi request. * Dùng để tự động gắn Access Token vào header từ localStorage/Store. */ headerTokenHandler?: (request: InternalAxiosRequestConfig) => void | Promise; refreshTimeout?: number; /** * error code refresh token. * @default [401] */ statusCodes?: number[]; /** * log debug interceptor. * @default false */ debug?: boolean; /** * [OPTIONAL] Check if the token in storage is valid. * Used for Cross-Tab Synchronization. * * If this returns a string (the token), we skip the refresh and use this token. * If this returns null/false, we proceed with the refresh. */ checkTokenIsValid?: () => Promise | string | null | false; } /** * Applies the authentication interceptor to an Axios instance. * * @param axiosInstance - The Axios instance to intercept. * @param config - Configuration for the interceptor. * * @example * ```ts * applyAuthTokenInterceptor(axios, { * requestRefresh: myRefreshFunction, * onSuccess: (tokens) => saveTokens(tokens), * onFailure: () => logout(), * }); * ``` */ declare const applyAuthTokenInterceptor: (axiosInstance: AxiosInstance, config: AuthInterceptorConfig) => void; export { type AuthInterceptorConfig, type AuthTokens, applyAuthTokenInterceptor };