fix forum

This commit is contained in:
2025-02-14 09:06:22 +08:00
parent f9e72a51bb
commit eb335533eb
11 changed files with 350 additions and 59 deletions

View File

@@ -1,3 +1,4 @@
import { apiGetUserProfile } from './../../user/lib/api_user';
export const apiGetUserId = async () => {
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
if (!token) return await token.json().catch(() => null);
@@ -58,3 +59,43 @@ export const apiGetAllUserWithExceptId = async ({
});
return await response.json().catch(() => null);
};
export const apiGetUserById = async ({ id }: { id: string }) => {
try {
// Fetch token from cookie
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
if (!token) {
console.error("No token found");
return null;
}
// Send PUT request to update portfolio logo
const response = await fetch(`/api/user/${id}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
Authorization: `Bearer ${token}`,
},
});
// Check if the response is OK
if (!response.ok) {
const errorData = await response.json().catch(() => null);
console.error(
"Failed to get user",
response.statusText,
errorData
);
throw new Error(
errorData?.message || "Failed to get user"
);
}
// Return the JSON response
return await response.json();
} catch (error) {
console.error("Error get user:", error);
throw error; // Re-throw the error to handle it in the calling function
}
};