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

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 tokenValue = await getToken();
  const token = tokenValue ? tokenValue : "";

  config.headers.Authorization = "Bearer " + token;
  return config;
});

export default axiosInstance;
