import axios from "axios";
import { getToken } from "./func";

const axiosInstance = axios.create({
  baseURL: import.meta.env.VITE_BASE_URL,
});

axiosInstance.interceptors.response.use(
  (response) => response,
  (error) => {
    return Promise.reject(error);
  }
);

axiosInstance.interceptors.request.use(async function (config) {
  const token = getToken();

  config.headers.Authorization = "Bearer " + token;
  config.headers["x-business-id"] = localStorage.getItem(
    import.meta.env.VITE_WORKSPACE_ID
  );
  return config;
});

export default axiosInstance;
