Merge pull request #227 from bipproduction/fix/bug/middleware
fix ( middleware )
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
"use server";
|
||||
|
||||
import { jwtVerify } from "jose";
|
||||
import { cookies } from "next/headers";
|
||||
import { decrypt } from "../../../../app/auth/_lib/decrypt";
|
||||
|
||||
@@ -16,21 +15,3 @@ export async function funGetUserIdByToken() {
|
||||
return cekUser?.id;
|
||||
}
|
||||
|
||||
// async function decrypt({
|
||||
// token,
|
||||
// encodedKey,
|
||||
// }: {
|
||||
// token: string;
|
||||
// encodedKey: string;
|
||||
// }): Promise<Record<string, any> | null> {
|
||||
// try {
|
||||
// const enc = new TextEncoder().encode(encodedKey);
|
||||
// const { payload } = await jwtVerify(token, enc, {
|
||||
// algorithms: ["HS256"],
|
||||
// });
|
||||
// return (payload.user as Record<string, any>) || null;
|
||||
// } catch (error) {
|
||||
// console.error("Gagal verifikasi session", error);
|
||||
// return null;
|
||||
// }
|
||||
// }
|
||||
|
||||
16
src/app_modules/_global/lib/api_image.ts
Normal file
16
src/app_modules/_global/lib/api_image.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
export const apiDeleteImageById = async ({
|
||||
fileId,
|
||||
dirId,
|
||||
}: {
|
||||
fileId: string;
|
||||
dirId?: string;
|
||||
}) => {
|
||||
const response = await fetch(`/api/image/delete`, {
|
||||
method: "DELETE",
|
||||
body: JSON.stringify({ fileId, dirId }),
|
||||
});
|
||||
|
||||
console.log("delete api =>", await response.json());
|
||||
|
||||
return await response.json().catch(() => null);
|
||||
};
|
||||
@@ -1,9 +1,39 @@
|
||||
export const apiGetUserId = async () => {
|
||||
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
|
||||
if (!token) return await token.json().catch(() => null);
|
||||
|
||||
const response = await fetch(`/api/user`, {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Accept: "application/json",
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
|
||||
console.log("Ini di pemanggilan API",await response.json());
|
||||
|
||||
if (!response.ok) return null;
|
||||
const data: Record<string, any> = await response.json();
|
||||
return data;
|
||||
};
|
||||
|
||||
export const apiGetCookiesUser = async () => {
|
||||
const response = await fetch(`/api/user/get`);
|
||||
return await response.json().catch(() => null);
|
||||
};
|
||||
|
||||
export const apiGetACtivationUser = async () => {
|
||||
const response = await fetch(`/api/user/activation`);
|
||||
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
|
||||
if (!token) return await token.json().catch(() => null);
|
||||
|
||||
const response = await fetch(`/api/user/activation`, {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Accept: "application/json",
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
return await response.json().catch(() => null);
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user