ADD: Cookie to header
This commit is contained in:
@@ -1,11 +1,24 @@
|
|||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
|
|
||||||
export const BelongingService = {
|
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) => {
|
getBelonging: async (belongingId) => {
|
||||||
const config = {
|
const config = {
|
||||||
method: 'get',
|
method: 'get',
|
||||||
url: '/api/belongings/admin/get-one/' + belongingId,
|
url: '/api/belongings/admin/get-one/' + belongingId,
|
||||||
withCredentials: true
|
withCredentials: true,
|
||||||
|
headers: BelongingService._getAuthHeader()
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
const response = await axios(config);
|
const response = await axios(config);
|
||||||
@@ -14,11 +27,13 @@ export const BelongingService = {
|
|||||||
console.log(err);
|
console.log(err);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
getAllBelongings: async () => {
|
getAllBelongings: async () => {
|
||||||
const config = {
|
const config = {
|
||||||
method: 'get',
|
method: 'get',
|
||||||
url: '/api/belongings/admin/get-all',
|
url: '/api/belongings/admin/get-all',
|
||||||
withCredentials: true
|
withCredentials: true,
|
||||||
|
headers: BelongingService._getAuthHeader()
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
const response = await axios(config);
|
const response = await axios(config);
|
||||||
@@ -27,12 +42,14 @@ export const BelongingService = {
|
|||||||
console.log(err);
|
console.log(err);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
searchBelongings: async (query) => {
|
searchBelongings: async (query) => {
|
||||||
const config = {
|
const config = {
|
||||||
method: 'get',
|
method: 'get',
|
||||||
url: '/api/belongings/admin/search',
|
url: '/api/belongings/admin/search',
|
||||||
withCredentials: true,
|
withCredentials: true,
|
||||||
params: query
|
params: query,
|
||||||
|
headers: BelongingService._getAuthHeader()
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
const response = await axios(config);
|
const response = await axios(config);
|
||||||
@@ -41,11 +58,13 @@ export const BelongingService = {
|
|||||||
console.log(err);
|
console.log(err);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
indexBelongings: async () => {
|
indexBelongings: async () => {
|
||||||
const config = {
|
const config = {
|
||||||
method: 'post',
|
method: 'post',
|
||||||
url: '/api/belongings/admin/index-all',
|
url: '/api/belongings/admin/index-all',
|
||||||
withCredentials: true
|
withCredentials: true,
|
||||||
|
headers: BelongingService._getAuthHeader()
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
const response = await axios(config);
|
const response = await axios(config);
|
||||||
@@ -54,12 +73,14 @@ export const BelongingService = {
|
|||||||
console.log(err);
|
console.log(err);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
createBelonging: async (data) => {
|
createBelonging: async (data) => {
|
||||||
const config = {
|
const config = {
|
||||||
method: 'post',
|
method: 'post',
|
||||||
url: '/api/belongings/admin/create',
|
url: '/api/belongings/admin/create',
|
||||||
withCredentials: true,
|
withCredentials: true,
|
||||||
data
|
data,
|
||||||
|
headers: BelongingService._getAuthHeader()
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
const response = await axios(config);
|
const response = await axios(config);
|
||||||
@@ -69,12 +90,14 @@ export const BelongingService = {
|
|||||||
return err.response.data.message;
|
return err.response.data.message;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
updateBelonging: async (belongingId, data) => {
|
updateBelonging: async (belongingId, data) => {
|
||||||
const config = {
|
const config = {
|
||||||
method: 'put',
|
method: 'put',
|
||||||
url: '/api/belongings/admin/update/' + belongingId,
|
url: '/api/belongings/admin/update/' + belongingId,
|
||||||
withCredentials: true,
|
withCredentials: true,
|
||||||
data
|
data,
|
||||||
|
headers: BelongingService._getAuthHeader()
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
const response = await axios(config);
|
const response = await axios(config);
|
||||||
|
|||||||
Reference in New Issue
Block a user