import { whitelistedPaths } from "./auth/whitelistedPaths.internal.mjs";
import { getAccessToken, getMergedConfig } from "./apiHelpers.mjs";
import Axios from "axios";
//#region src/utilities/axiosInterceptors.js
const axiosInterceptors = () => {
	Axios.interceptors.request.use(async (config) => {
		if (!whitelistedPaths.includes(window.location.pathname)) {
			let accessToken = "";
			if (!config?.headers?.Authorization) accessToken = await getAccessToken();
			return getMergedConfig(accessToken, config);
		}
		return config;
	}, (error) => Promise.reject(error));
	Axios.interceptors.response.use((response) => response, async (error) => {
		const config = error?.config;
		if (error?.response?.status === 401 && !config?._retry && !whitelistedPaths.includes(window.location.pathname)) {
			config.headers.Authorization = `Bearer ${await getAccessToken()}`;
			config._retry = true;
			return Axios(config);
		}
		return Promise.reject(error);
	});
};
//#endregion
export { axiosInterceptors as default };

//# sourceMappingURL=axiosInterceptors.mjs.map