aboutsummaryrefslogtreecommitdiff
path: root/web/src/utils
diff options
context:
space:
mode:
authorAndrew Lee <andrew@alee14.me>2025-03-25 17:23:30 -0400
committerAndrew Lee <andrew@alee14.me>2025-03-25 17:23:30 -0400
commit2c783bdb703e4ad69c9f3f846c2c9e6a527ccc80 (patch)
treee02587b4dca4bd7027b4cc012d458b18392643ea /web/src/utils
parent1c12d378d66b92b1674acd17640f2bac752da289 (diff)
downloadAleeBot-2c783bdb703e4ad69c9f3f846c2c9e6a527ccc80.tar.gz
AleeBot-2c783bdb703e4ad69c9f3f846c2c9e6a527ccc80.tar.bz2
AleeBot-2c783bdb703e4ad69c9f3f846c2c9e6a527ccc80.zip
Implemented admin dashboard
Diffstat (limited to 'web/src/utils')
-rw-r--r--web/src/utils/api.js29
1 files changed, 29 insertions, 0 deletions
diff --git a/web/src/utils/api.js b/web/src/utils/api.js
new file mode 100644
index 0000000..4ba0e0c
--- /dev/null
+++ b/web/src/utils/api.js
@@ -0,0 +1,29 @@
+// Utility for making authenticated API requests
+export const fetchWithAuth = async (endpoint, options = {}) => {
+ const token = localStorage.getItem('token');
+ const apiUrl = localStorage.getItem('apiUrl');
+
+ if (!token || !apiUrl) {
+ throw new Error('Not authenticated');
+ }
+
+ const headers = {
+ 'Content-Type': 'application/json',
+ 'Authorization': `Bearer ${token}`,
+ ...options.headers
+ };
+
+ const response = await fetch(`${apiUrl}${endpoint}`, {
+ ...options,
+ headers
+ });
+
+ // Handle token expiration
+ if (response.status === 401) {
+ localStorage.removeItem('token');
+ window.location.href = '/';
+ throw new Error('Session expired');
+ }
+
+ return response;
+};