import axios from "axios";

const baseURL = import.meta.env.VITE_API_BASE || "";

export const api = axios.create({
  baseURL: baseURL || undefined,
  withCredentials: true,
});

api.interceptors.request.use((config) => {
  const token = localStorage.getItem("qbuffer_token");
  if (token) {
    config.headers = config.headers || {};
    if (!config.headers.Authorization) {
      config.headers.Authorization = `Bearer ${token}`;
    }
  }
  return config;
});
