Skip to content

Commit

Permalink
fix: accessToken 헤더 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
doh-yo committed Jul 19, 2024
1 parent 4e951c4 commit a58628e
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/api/itemApi.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
const baseURL = "https://panda-market-api.vercel.app";

function getAccessToken() {
return localStorage.getItem("accessToken") || "";
}

export async function getProducts(params: Record<string, string> = {}) {
const query = new URLSearchParams(params).toString();

Expand Down Expand Up @@ -85,6 +89,7 @@ export async function postProductComment({
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${getAccessToken()}`,
},
body: JSON.stringify(requestBody),
});
Expand Down Expand Up @@ -125,6 +130,7 @@ export async function updateProductComment({
method: "PATCH",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${getAccessToken()}`,
},
body: JSON.stringify(requestBody),
});
Expand All @@ -151,6 +157,7 @@ export async function deleteProductComment(commentId: number) {
method: "DELETE",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${getAccessToken()}`,
},
});

Expand Down Expand Up @@ -183,6 +190,7 @@ export async function uploadProduct(newProduct: NewProduct) {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${getAccessToken()}`,
},
body: JSON.stringify(newProduct),
});
Expand All @@ -209,6 +217,9 @@ export async function uploadImage(imageFile: File) {
try {
const response = await fetch(`${baseURL}/images/upload`, {
method: "POST",
headers: {
Authorization: `Bearer ${getAccessToken()}`,
},
body: formData,
});

Expand All @@ -217,7 +228,7 @@ export async function uploadImage(imageFile: File) {
}

const body = await response.json();
return body.url; // Assuming the response contains the URL of the uploaded image
return body.url;
} catch (error) {
console.error("Failed to upload image:", error);
throw error;
Expand Down

0 comments on commit a58628e

Please sign in to comment.