modul-s / src /lib /apiClient.ts
sitcod3's picture
Upload src/lib/apiClient.ts with huggingface_hub
4dbfff9 verified
Raw History Blame Contribute Delete
753 Bytes
import axios from "axios";
export const apiClient = axios.create({
baseURL: "/api",
});
apiClient.interceptors.request.use((config) => {
// Only access localStorage in browser environment
if (typeof window !== 'undefined') {
const keysStr = localStorage.getItem("smartlead_api_keys");
const activeId = localStorage.getItem("smartlead_active_key_id");
if (keysStr && activeId) {
try {
const keys = JSON.parse(keysStr);
const activeKey = keys.find((k: any) => k.id === activeId)?.key;
if (activeKey) {
config.headers["x-api-key"] = activeKey;
}
} catch (e) {
console.error("Failed to parse API keys", e);
}
}
}
return config;
});