UNPKG

axios-cookie-auth

Version:

A lightweight Axios helper for managing httpOnly cookies and automatic token refresh with retries in TypeScript.

14 lines (13 loc) 889 B
import { AxiosInstance } from "axios"; /** * Custom hook for creating an Axios instance with error handling, token refresh, and HTTP-only cookie support. * * @param baseURL - The base URL for all API requests. * @param refreshEndpoint - The endpoint used to refresh the authentication token. * @param useCsrf - Whether to include CSRF token protection for modifying requests (false by default) * @param headers - Optional custom headers to include in each request. * @param logoutFn - Optional callback function to call when the authentication token refresh fails (e.g., logging out the user). * * @returns The Axios instance configured with interceptors for token refresh, CSRF protection, and error handling. */ export declare function useApi(baseURL: string, refreshEndpoint: string, headers?: Record<string, string>, useCsrf?: boolean, logoutFn?: () => void): AxiosInstance;