'use client'

//export const url = 'http://localhost/BK-API/';
export const url = 'https://league.worldsoft.host/';

export const IMAGEURL = 'https://league.worldsoft.host/';


import axios from "axios";
import { getValidAuthTokens } from "./features/login/session";


export const client = axios.create({
  baseURL: url,

  headers: {
    'Content-Type': 'application/json',
  }
})

const axiosInstance = axios.create({
  baseURL: url, // Replace with your API base URL
  headers: { 'Content-Type': 'application/json' }
});

axiosInstance.interceptors.request.use(
  async function (config) {

    const { token } = await getValidAuthTokens();
    if (token) {
      config.headers.Authorization = `Bearer ${token}`;
    }

    return config;
  },
  function (error) {
    // Handle the error
    return Promise.reject(error);
  }
);


export default axiosInstance;

