1.1.2 • Published 11 months ago

@plansis/axios-auth-refresh v1.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

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: {
    statusCodes: [401, 403],
    retryDelayMs: 300,
    maxRetryCount: 3,
    maxCallCount: 3,
  },
});
1.1.0

11 months ago

1.0.10

1 year ago

1.0.7

1 year ago

1.0.5

1 year ago

1.1.2

11 months ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago