forked from microsoft/github-copilot-vibe-coding-workshop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapiClient.js
More file actions
33 lines (30 loc) · 733 Bytes
/
apiClient.js
File metadata and controls
33 lines (30 loc) · 733 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import axios from "axios";
const apiClient = axios.create({
baseURL: "/api",
headers: {
"Content-Type": "application/json",
},
});
apiClient.interceptors.request.use(
(config) => {
const userStr = localStorage.getItem("user");
if (userStr) {
try {
const user = JSON.parse(userStr);
if (user.userId) {
config.headers["X-User-ID"] = user.userId;
}
if (user.username) {
config.headers["x-username"] = encodeURIComponent(user.username);
}
} catch (error) {
console.error("Error parsing user information:", error);
}
}
return config;
},
(error) => {
return Promise.reject(error);
}
);
export default apiClient;