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

const axiosInstance = axios.create({
  // baseURL: process.env.NEXT_PUBLIC_BASE_URL,
  baseURL: 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;
