fix ( middleware )

deskripsi:
- fix access api melalui middleware di: home, profile dan portofolio
This commit is contained in:
2025-01-08 10:39:18 +08:00
parent 18bd4efed1
commit cccb011da5
36 changed files with 1206 additions and 450 deletions

View File

@@ -1,4 +1,17 @@
export const apiGetDataHome = async (path?: string) => {
const response = await fetch(`/api/new/home${(path) ? path : ''}`)
return await response.json().catch(() => null)
}
export const apiGetDataHome = async ({ path }: { path?: string }) => {
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
if (!token) return await token.json().catch(() => null);
const response = await fetch(`/api/new/home${path ? path : ""}`, {
headers: {
"Content-Type": "application/json",
Accept: "application/json",
"Access-Control-Allow-Origin": "*",
Authorization: `Bearer ${token}`,
},
});
if (!response.ok) return null;
const data: Record<string, any> = await response.json();
return data;
};