sitcod3 commited on
Commit
4dbfff9
·
verified ·
1 Parent(s): 882d2b8

Upload src/lib/apiClient.ts with huggingface_hub

Browse files
Files changed (1) hide show
  1. src/lib/apiClient.ts +27 -0
src/lib/apiClient.ts ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import axios from "axios";
2
+
3
+ export const apiClient = axios.create({
4
+ baseURL: "/api",
5
+ });
6
+
7
+ apiClient.interceptors.request.use((config) => {
8
+ // Only access localStorage in browser environment
9
+ if (typeof window !== 'undefined') {
10
+ const keysStr = localStorage.getItem("smartlead_api_keys");
11
+ const activeId = localStorage.getItem("smartlead_active_key_id");
12
+
13
+ if (keysStr && activeId) {
14
+ try {
15
+ const keys = JSON.parse(keysStr);
16
+ const activeKey = keys.find((k: any) => k.id === activeId)?.key;
17
+ if (activeKey) {
18
+ config.headers["x-api-key"] = activeKey;
19
+ }
20
+ } catch (e) {
21
+ console.error("Failed to parse API keys", e);
22
+ }
23
+ }
24
+ }
25
+
26
+ return config;
27
+ });