@plansis/axios-auth-refresh
TypeScript icon, indicating that this package has built-in type declarations

1.0.10 • Public • Published

axios-auth-refresh

Этот простой модуль обеспечивает отправку единого запроса на обновление токена даже при обработке одновременных запросов. Кроме того, он предлагает методы для последовательной интеграции запросов Axios с различными библиотеками.

Basic Usage

import axios from "axios";
import { axiosAuthRefresh } from "@plansis/axios-auth-refresh";

const axiosInstance = axios.create({
  withCredentials: true,
  baseURL: "https://example.com/api",
});

const handleRefreshAuthCall = async () => {
  const response = await axiosInstance.post<TData>(
    "/refresh",
    {},
    { skipAuthRefresh: true }
  );
  return response;
};

const onRefreshSuccess = (res: AxiosResponse<TData>) => {
  console.log("success:", res);
};

const onRefreshError = (err: AxiosError<TError>) => {
  console.log("error:", err);
};

axiosAuthRefresh<TData, TError>({
  axiosInstance,
  refreshAuthCall: handleRefreshAuthCall,
  onSuccess: onRefreshSuccess,
  onError: onRefreshError,
  options: {
    retry: 3,
    retryDelay: 300,
    statusCodes: [401, 403],
  },
});

/@plansis/axios-auth-refresh/

    Package Sidebar

    Install

    npm i @plansis/axios-auth-refresh

    Weekly Downloads

    203

    Version

    1.0.10

    License

    MIT

    Unpacked Size

    10.9 kB

    Total Files

    16

    Last publish

    Collaborators

    • plansis