Seth0330 commited on
Commit
1c3e70d
·
verified ·
1 Parent(s): 1d68698

Update frontend/src/services/api.js

Browse files
Files changed (1) hide show
  1. frontend/src/services/api.js +12 -1
frontend/src/services/api.js CHANGED
@@ -4,6 +4,14 @@
4
 
5
  const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || "";
6
 
 
 
 
 
 
 
 
 
7
  /**
8
  * Extract data from a document
9
  * @param {File} file - The file to extract data from
@@ -19,6 +27,7 @@ export async function extractDocument(file, keyFields = "") {
19
 
20
  const response = await fetch(`${API_BASE_URL}/api/extract`, {
21
  method: "POST",
 
22
  body: formData,
23
  });
24
 
@@ -37,7 +46,9 @@ export async function extractDocument(file, keyFields = "") {
37
  * @returns {Promise<Array>} Array of extraction records
38
  */
39
  export async function getHistory() {
40
- const response = await fetch(`${API_BASE_URL}/api/history`);
 
 
41
 
42
  if (!response.ok) {
43
  const errorData = await response.json().catch(() => ({
 
4
 
5
  const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || "";
6
 
7
+ /**
8
+ * Get authorization headers with token
9
+ */
10
+ function getAuthHeaders() {
11
+ const token = localStorage.getItem("auth_token");
12
+ return token ? { Authorization: `Bearer ${token}` } : {};
13
+ }
14
+
15
  /**
16
  * Extract data from a document
17
  * @param {File} file - The file to extract data from
 
27
 
28
  const response = await fetch(`${API_BASE_URL}/api/extract`, {
29
  method: "POST",
30
+ headers: getAuthHeaders(),
31
  body: formData,
32
  });
33
 
 
46
  * @returns {Promise<Array>} Array of extraction records
47
  */
48
  export async function getHistory() {
49
+ const response = await fetch(`${API_BASE_URL}/api/history`, {
50
+ headers: getAuthHeaders(),
51
+ });
52
 
53
  if (!response.ok) {
54
  const errorData = await response.json().catch(() => ({