ADD: Cookie to header

This commit is contained in:
2025-04-29 23:36:30 +03:30
parent b1ad3ef174
commit 80ff890744
+29 -6
View File
@@ -1,11 +1,24 @@
import axios from 'axios';
export const BelongingService = {
// Helper function to get token from cookies
_getAuthHeader: () => {
const bmToken = document.cookie
.split('; ')
.find((row) => row.startsWith('bm-token='))
?.split('=')[1];
return {
Authorization: `Bearer ${bmToken}`
};
},
getBelonging: async (belongingId) => {
const config = {
method: 'get',
url: '/api/belongings/admin/get-one/' + belongingId,
withCredentials: true
withCredentials: true,
headers: BelongingService._getAuthHeader()
};
try {
const response = await axios(config);
@@ -14,11 +27,13 @@ export const BelongingService = {
console.log(err);
}
},
getAllBelongings: async () => {
const config = {
method: 'get',
url: '/api/belongings/admin/get-all',
withCredentials: true
withCredentials: true,
headers: BelongingService._getAuthHeader()
};
try {
const response = await axios(config);
@@ -27,12 +42,14 @@ export const BelongingService = {
console.log(err);
}
},
searchBelongings: async (query) => {
const config = {
method: 'get',
url: '/api/belongings/admin/search',
withCredentials: true,
params: query
params: query,
headers: BelongingService._getAuthHeader()
};
try {
const response = await axios(config);
@@ -41,11 +58,13 @@ export const BelongingService = {
console.log(err);
}
},
indexBelongings: async () => {
const config = {
method: 'post',
url: '/api/belongings/admin/index-all',
withCredentials: true
withCredentials: true,
headers: BelongingService._getAuthHeader()
};
try {
const response = await axios(config);
@@ -54,12 +73,14 @@ export const BelongingService = {
console.log(err);
}
},
createBelonging: async (data) => {
const config = {
method: 'post',
url: '/api/belongings/admin/create',
withCredentials: true,
data
data,
headers: BelongingService._getAuthHeader()
};
try {
const response = await axios(config);
@@ -69,12 +90,14 @@ export const BelongingService = {
return err.response.data.message;
}
},
updateBelonging: async (belongingId, data) => {
const config = {
method: 'put',
url: '/api/belongings/admin/update/' + belongingId,
withCredentials: true,
data
data,
headers: BelongingService._getAuthHeader()
};
try {
const response = await axios(config);