fix ( user access )

deskripsi:
- membatasi akses user yang hanya bisa di berikan oleh admin
This commit is contained in:
2025-01-10 08:49:30 +08:00
parent d0716bd859
commit abe92e4ad2
22 changed files with 744 additions and 218 deletions

View File

@@ -1,11 +1,14 @@
"use server";
import prisma from "@/app/lib/prisma";
import backendLogger from "@/util/backendLogger";
import { revalidatePath } from "next/cache";
import { headers } from "next/headers";
export default async function adminUserAccess_funEditAccess(
userId: string,
value: boolean
value: boolean,
nomor?: string
) {
const updt = await prisma.user.update({
where: {
@@ -16,6 +19,31 @@ export default async function adminUserAccess_funEditAccess(
},
});
const headersList = headers();
const host = headersList.get("host");
const protocol = headersList.get("x-forwarded-proto") || "http";
const path = headersList.get("x-invoke-path");
const baseUrl = `${protocol}://${host}`;
// const fullUrl = `${protocol}://${host}${path}`;
if (value === true) {
const message = `Hallo rekan HIPMI, Anda telah diberikan akses ke HIPMI Apps. Silakan mulai jelajahi fitur-fitur yang tersedia melalui link berikut: ${baseUrl}`;
const encodedMessage = encodeURIComponent(message);
const res = await fetch(
`https://wa.wibudev.com/code?nom=${nomor}&text=${encodedMessage}
`
);
if (!res.ok) {
backendLogger.error("Error send message", res);
}
const result = await res.json();
backendLogger.info("Success send message", result);
}
if (!updt) return { status: 400, message: "Update gagal" };
revalidatePath("/dev/admin/user-access");
return { status: 200, message: "Update berhasil" };