axios-auth-refresh
Version:
Axios plugin which makes it very easy to automatically refresh the authorization tokens of your clients
23 lines (22 loc) • 1.66 kB
TypeScript
import { AxiosInstance } from 'axios';
import { AxiosAuthRefreshOptions } from './model';
export { AxiosAuthRefreshOptions, AxiosAuthRefreshRequestConfig } from './model';
/**
* Creates an authentication refresh interceptor that binds to any error response.
* If the response status code is one of the options.statusCodes, interceptor calls the refreshAuthCall
* which must return a Promise. While refreshAuthCall is running, all the new requests are intercepted and are waiting
* for the refresh call to resolve. While running the refreshing call, the instance provided is marked as a paused instance
* which indicates the interceptor to not intercept any responses from it. This is because you'd otherwise need to mark
* the specific requests you make by yourself to make sure it's not intercepted. This behavior can be
* turned off, but use it with caution as you need to mark the requests with the ` skipAuthRefresh ` flag yourself to
* not run into interceptors loop.
*
* @param {AxiosInstance} instance - Axios HTTP client instance
* @param {(error: any) => Promise<AxiosPromise>} refreshAuthCall - refresh token call which must return a Promise
* @param {AxiosAuthRefreshOptions} options - options for the interceptor @see defaultOptions
* @return {number} - interceptor id (in case you want to eject it manually)
*/
export declare function createAuthRefresh(instance: AxiosInstance, refreshAuthCall: (error: any) => Promise<any>, options?: AxiosAuthRefreshOptions): number;
/** @deprecated Use createAuthRefresh instead */
export declare const createAuthRefreshInterceptor: typeof createAuthRefresh;
export default createAuthRefresh;