import axios from "axios";

export const getUserId = () => {
  let id = localStorage.getItem("poster_picker_uid");
  if (!id) {
    id = crypto.randomUUID();
    localStorage.setItem("poster_picker_uid", id);
  }
  return id;
};

const api = axios.create({
  baseURL: process.env.REACT_APP_API_URL,
  withCredentials: true,
});

api.interceptors.request.use((config) => {
  config.headers["X-User-ID"] = getUserId();
  return config;
});

export default api;
