diff --git a/CHANGELOG.md b/CHANGELOG.md index a9cc1c25f..c6c0c2fd4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [[v2.40.11](https://github.com/multiversx/mx-sdk-dapp/pull/1280)] - 2024-10-09 +- [Fixed axios interceptor concurrent calls](https://github.com/multiversx/mx-sdk-dapp/pull/1279) + ## [[v2.40.10](https://github.com/multiversx/mx-sdk-dapp/pull/1277)] - 2024-10-04 - [Update WalletConnect Provider](https://github.com/multiversx/mx-sdk-dapp/pull/1276) diff --git a/package.json b/package.json index 3add9424a..4e848eeaf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@multiversx/sdk-dapp", - "version": "2.40.10", + "version": "2.40.11", "description": "A library to hold the main logic for a dapp on the MultiversX blockchain", "author": "MultiversX", "license": "GPL-3.0-or-later", diff --git a/src/wrappers/AxiosInterceptorContext/components/AxiosInterceptor.tsx b/src/wrappers/AxiosInterceptorContext/components/AxiosInterceptor.tsx index fc48df3cf..469c35cc7 100644 --- a/src/wrappers/AxiosInterceptorContext/components/AxiosInterceptor.tsx +++ b/src/wrappers/AxiosInterceptorContext/components/AxiosInterceptor.tsx @@ -1,4 +1,4 @@ -import React, { useRef, PropsWithChildren, useEffect } from 'react'; +import React, { useRef, PropsWithChildren, useMemo } from 'react'; import axios from 'axios'; import { useAxiosInterceptorContext } from './AxiosInterceptorContextProvider'; @@ -15,7 +15,7 @@ export const AxiosInterceptor = ({ const requestIdRef = useRef(-1); - const setResponseInterceptors = () => { + requestIdRef.current = useMemo(() => { axios.interceptors.response.use( (response) => { return response; @@ -30,15 +30,16 @@ export const AxiosInterceptor = ({ return Promise.reject(error); } ); - }; - const setInterceptors = () => { axios.interceptors.request.eject(requestIdRef.current); - requestIdRef.current = axios.interceptors.request.use( + return axios.interceptors.request.use( async (config) => { - if (authenticatedDomains.includes(String(config?.baseURL))) { - config.headers.set('Authorization', `Bearer ${bearerToken}`); + if ( + authenticatedDomains.includes(String(config?.baseURL)) && + bearerToken + ) { + config.headers.Authorization = `Bearer ${bearerToken}`; } return config; @@ -47,15 +48,7 @@ export const AxiosInterceptor = ({ Promise.reject(error); } ); - }; - - useEffect(setResponseInterceptors, []); - - useEffect(() => { - if (bearerToken) { - setInterceptors(); - } - }, [bearerToken]); + }, [bearerToken, authenticatedDomains]); return <>{children}; };