UNPKG

axios-token-refresh

Version:

A lightweight utility for Axios to handle token refresh logic seamlessly. Automatically retries requests after token expiration with customizable retry logic and status code handling.

28 lines (22 loc) 1.05 kB
// Generated by dts-bundle-generator v9.5.1 import { AxiosError, AxiosInstance, AxiosRequestConfig } from 'axios'; declare const registerAxiosTokenRefresh: (instance: Omit<AxiosInstance, "create"> & { create?: AxiosInstance["create"]; }, options: AxiosTFOptions) => number; export interface AxiosTFOptions { /** The function that will be called to refresh the token. It should return a promise */ refreshRequest: (error: any) => Promise<any>; /** List status code which u want to handle refresh. Default is [401] */ statusCodes?: number[]; /** Determine whether to refresh. `statusCodesToRetry` will be ignored when u use this config */ shouldRetry?: (error: AxiosError) => boolean; /** The number of times to retry the request. Default is 1 */ retryTimes?: number; /** The callback function called before each `refreshRequest` */ onRetry?: (requestConfig: AxiosRequestConfig) => AxiosRequestConfig | Promise<AxiosRequestConfig>; } export { registerAxiosTokenRefresh as default, }; export as namespace AxiosTokenRefresh; export {};