import axios from 'axios';

const api = axios.create({
  baseURL: 'http://happy-homes.sslinsight.com/api',
  withCredentials: true, // Allows credentials (cookies, etc.) to be sent with requests.
});

api.interceptors.request.use((config) => {
  const token = typeof window !== "undefined" ? localStorage.getItem('userToken') : null;
  
  if (token) {
    config.headers.Authorization = `Bearer ${token}`;
  }

  console.log('Request headers:', config.headers); // Log request headers for debugging
  return config;
});

export default api;
