import axios from "axios" import {useAuthStore} from "@/stores/authStore.js" export function useClient() { if (!import.meta.env.VITE_API_URL) throw new Error("VITE_API_URL is not provided") // You create a .env.development file and a .env file // depending on the environment, the correct file will be used const api = axios.create({ baseURL: import.meta.env.VITE_API_URL, timeout: 10000, }); const authStore = useAuthStore() const requestInterceptor = (config) => { if (authStore.isAuthenticated) { config.headers["Authorization"] = `Bearer ${authStore.accessToken}` } return config } api.interceptors.request.use(requestInterceptor); return api; }