import { useAuthStore } from "../stores/auth";

export function useAuthFetch() {
  function authFetch(url, options = {}) {
    const auth = useAuthStore();
    const headers = {
      "Content-Type": "application/json",
      ...(options.headers || {}),
    };
    if (auth.token) headers["Authorization"] = `Bearer ${auth.token}`;
    return fetch(url, { ...options, headers });
  }

  return { authFetch };
}
