fix ( user access )
deskripsi: - membatasi akses user yang hanya bisa di berikan oleh admin
This commit is contained in:
@@ -87,6 +87,7 @@
|
|||||||
"react-quill": "^2.0.0",
|
"react-quill": "^2.0.0",
|
||||||
"react-responsive-carousel": "^3.2.23",
|
"react-responsive-carousel": "^3.2.23",
|
||||||
"react-toastify": "^9.1.3",
|
"react-toastify": "^9.1.3",
|
||||||
|
"sharp": "^0.33.5",
|
||||||
"socket.io-client": "^4.7.2",
|
"socket.io-client": "^4.7.2",
|
||||||
"tailwindcss": "3.3.3",
|
"tailwindcss": "3.3.3",
|
||||||
"ts-node": "^10.9.2",
|
"ts-node": "^10.9.2",
|
||||||
|
|||||||
198
prisma/migrations/20250108154615_new_database/migration.sql
Normal file
198
prisma/migrations/20250108154615_new_database/migration.sql
Normal file
@@ -0,0 +1,198 @@
|
|||||||
|
/*
|
||||||
|
Warnings:
|
||||||
|
|
||||||
|
- You are about to drop the column `imagesId` on the `Job` table. All the data in the column will be lost.
|
||||||
|
- You are about to drop the column `active` on the `MasterBank` table. All the data in the column will be lost.
|
||||||
|
- You are about to drop the column `name` on the `MasterBank` table. All the data in the column will be lost.
|
||||||
|
- You are about to drop the column `imagesBackgroundId` on the `Profile` table. All the data in the column will be lost.
|
||||||
|
- You are about to drop the column `imagesId` on the `Profile` table. All the data in the column will be lost.
|
||||||
|
- You are about to drop the `ImagesBackground` table. If the table is not empty, all the data it contains will be lost.
|
||||||
|
- Added the required column `namaAkun` to the `MasterBank` table without a default value. This is not possible if the table is not empty.
|
||||||
|
- Added the required column `namaBank` to the `MasterBank` table without a default value. This is not possible if the table is not empty.
|
||||||
|
|
||||||
|
*/
|
||||||
|
-- DropForeignKey
|
||||||
|
ALTER TABLE "Job" DROP CONSTRAINT "Job_imagesId_fkey";
|
||||||
|
|
||||||
|
-- DropForeignKey
|
||||||
|
ALTER TABLE "Notifikasi" DROP CONSTRAINT "NotifikasiAdmin";
|
||||||
|
|
||||||
|
-- DropForeignKey
|
||||||
|
ALTER TABLE "Notifikasi" DROP CONSTRAINT "NotifikasiUser";
|
||||||
|
|
||||||
|
-- DropForeignKey
|
||||||
|
ALTER TABLE "Portofolio" DROP CONSTRAINT "Portofolio_logoId_fkey";
|
||||||
|
|
||||||
|
-- DropForeignKey
|
||||||
|
ALTER TABLE "Profile" DROP CONSTRAINT "Profile_imagesBackgroundId_fkey";
|
||||||
|
|
||||||
|
-- DropForeignKey
|
||||||
|
ALTER TABLE "Profile" DROP CONSTRAINT "Profile_imagesId_fkey";
|
||||||
|
|
||||||
|
-- DropIndex
|
||||||
|
DROP INDEX "Profile_imagesBackgroundId_key";
|
||||||
|
|
||||||
|
-- DropIndex
|
||||||
|
DROP INDEX "Profile_imagesId_key";
|
||||||
|
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "BeritaInvestasi" ADD COLUMN "imageId" TEXT;
|
||||||
|
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "DokumenInvestasi" ADD COLUMN "fileId" TEXT,
|
||||||
|
ALTER COLUMN "url" DROP NOT NULL;
|
||||||
|
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "Donasi" ADD COLUMN "imageId" TEXT;
|
||||||
|
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "Donasi_Cerita" ADD COLUMN "imageId" TEXT;
|
||||||
|
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "Donasi_Invoice" ADD COLUMN "imageId" TEXT;
|
||||||
|
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "Donasi_Kabar" ADD COLUMN "imageId" TEXT;
|
||||||
|
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "Donasi_PencairanDana" ADD COLUMN "imageId" TEXT;
|
||||||
|
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "Donasi_TemporaryCreate" ADD COLUMN "imageId" TEXT;
|
||||||
|
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "Event" ADD COLUMN "isArsip" BOOLEAN DEFAULT false,
|
||||||
|
ADD COLUMN "tanggalSelesai" TIMESTAMP(3),
|
||||||
|
ALTER COLUMN "tanggal" DROP NOT NULL;
|
||||||
|
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "Event_Peserta" ADD COLUMN "isPresent" BOOLEAN NOT NULL DEFAULT false;
|
||||||
|
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "Investasi" ADD COLUMN "imageId" TEXT,
|
||||||
|
ADD COLUMN "prospektusFileId" TEXT;
|
||||||
|
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "Job" DROP COLUMN "imagesId",
|
||||||
|
ADD COLUMN "imageId" TEXT;
|
||||||
|
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "MasterBank" DROP COLUMN "active",
|
||||||
|
DROP COLUMN "name",
|
||||||
|
ADD COLUMN "isActive" BOOLEAN NOT NULL DEFAULT true,
|
||||||
|
ADD COLUMN "namaAkun" TEXT NOT NULL,
|
||||||
|
ADD COLUMN "namaBank" TEXT NOT NULL;
|
||||||
|
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "Notifikasi" ALTER COLUMN "userId" DROP NOT NULL,
|
||||||
|
ALTER COLUMN "adminId" DROP NOT NULL;
|
||||||
|
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "Profile" DROP COLUMN "imagesBackgroundId",
|
||||||
|
DROP COLUMN "imagesId",
|
||||||
|
ADD COLUMN "imageBackgroundId" TEXT,
|
||||||
|
ADD COLUMN "imageId" TEXT;
|
||||||
|
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "ProspektusInvestasi" ADD COLUMN "fileId" TEXT,
|
||||||
|
ADD COLUMN "title" TEXT;
|
||||||
|
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "User" ALTER COLUMN "active" SET DEFAULT false;
|
||||||
|
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "UserSession" ALTER COLUMN "expires" DROP NOT NULL;
|
||||||
|
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "Voting" ADD COLUMN "isArsip" BOOLEAN NOT NULL DEFAULT false;
|
||||||
|
|
||||||
|
-- DropTable
|
||||||
|
DROP TABLE "ImagesBackground";
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE "Investasi_Invoice" (
|
||||||
|
"id" TEXT NOT NULL,
|
||||||
|
"isActive" BOOLEAN NOT NULL DEFAULT true,
|
||||||
|
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||||
|
"nominal" TEXT NOT NULL,
|
||||||
|
"lembarTerbeli" TEXT NOT NULL,
|
||||||
|
"investasiId" TEXT,
|
||||||
|
"masterBankId" TEXT,
|
||||||
|
"statusInvoiceId" TEXT,
|
||||||
|
"authorId" TEXT,
|
||||||
|
"imagesId" TEXT,
|
||||||
|
"imageId" TEXT,
|
||||||
|
|
||||||
|
CONSTRAINT "Investasi_Invoice_pkey" PRIMARY KEY ("id")
|
||||||
|
);
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE "InvestasiMaster_StatusInvoice" (
|
||||||
|
"id" TEXT NOT NULL,
|
||||||
|
"name" TEXT NOT NULL,
|
||||||
|
"isActive" BOOLEAN NOT NULL DEFAULT true,
|
||||||
|
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||||
|
|
||||||
|
CONSTRAINT "InvestasiMaster_StatusInvoice_pkey" PRIMARY KEY ("id")
|
||||||
|
);
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE "BusinessMaps" (
|
||||||
|
"id" TEXT NOT NULL,
|
||||||
|
"isActive" BOOLEAN NOT NULL DEFAULT true,
|
||||||
|
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||||
|
"namePin" TEXT NOT NULL,
|
||||||
|
"latitude" DOUBLE PRECISION NOT NULL,
|
||||||
|
"longitude" DOUBLE PRECISION NOT NULL,
|
||||||
|
"authorId" TEXT,
|
||||||
|
"portofolioId" TEXT,
|
||||||
|
"imageId" TEXT,
|
||||||
|
"pinId" TEXT,
|
||||||
|
|
||||||
|
CONSTRAINT "BusinessMaps_pkey" PRIMARY KEY ("id")
|
||||||
|
);
|
||||||
|
|
||||||
|
-- CreateTable
|
||||||
|
CREATE TABLE "MasterKategoriApp" (
|
||||||
|
"id" TEXT NOT NULL,
|
||||||
|
"isActive" BOOLEAN NOT NULL DEFAULT true,
|
||||||
|
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||||
|
"name" TEXT NOT NULL,
|
||||||
|
"value" TEXT,
|
||||||
|
|
||||||
|
CONSTRAINT "MasterKategoriApp_pkey" PRIMARY KEY ("id")
|
||||||
|
);
|
||||||
|
|
||||||
|
-- CreateIndex
|
||||||
|
CREATE UNIQUE INDEX "BusinessMaps_portofolioId_key" ON "BusinessMaps"("portofolioId");
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "Investasi_Invoice" ADD CONSTRAINT "Investasi_Invoice_investasiId_fkey" FOREIGN KEY ("investasiId") REFERENCES "Investasi"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "Investasi_Invoice" ADD CONSTRAINT "Investasi_Invoice_masterBankId_fkey" FOREIGN KEY ("masterBankId") REFERENCES "MasterBank"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "Investasi_Invoice" ADD CONSTRAINT "Investasi_Invoice_statusInvoiceId_fkey" FOREIGN KEY ("statusInvoiceId") REFERENCES "InvestasiMaster_StatusInvoice"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "Investasi_Invoice" ADD CONSTRAINT "Investasi_Invoice_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "Investasi_Invoice" ADD CONSTRAINT "Investasi_Invoice_imagesId_fkey" FOREIGN KEY ("imagesId") REFERENCES "Images"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "Notifikasi" ADD CONSTRAINT "NotifikasiUser" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "Notifikasi" ADD CONSTRAINT "NotifikasiAdmin" FOREIGN KEY ("adminId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "BusinessMaps" ADD CONSTRAINT "BusinessMaps_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||||
|
|
||||||
|
-- AddForeignKey
|
||||||
|
ALTER TABLE "BusinessMaps" ADD CONSTRAINT "BusinessMaps_portofolioId_fkey" FOREIGN KEY ("portofolioId") REFERENCES "Portofolio"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||||
@@ -24,7 +24,7 @@ export async function POST(req: Request) {
|
|||||||
data: {
|
data: {
|
||||||
username: data.username,
|
username: data.username,
|
||||||
nomor: data.nomor,
|
nomor: data.nomor,
|
||||||
active: true,
|
active: false,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { funGetDirectoryNameByValue } from "@/app_modules/_global/fun/get";
|
import { funGetDirectoryNameByValue } from "@/app_modules/_global/fun/get";
|
||||||
import backendLogger from "@/util/backendLogger";
|
import backendLogger from "@/util/backendLogger";
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
|
import sharp from "sharp";
|
||||||
export async function POST(request: Request) {
|
export async function POST(request: Request) {
|
||||||
const formData = await request.formData();
|
const formData = await request.formData();
|
||||||
|
|
||||||
@@ -11,9 +12,30 @@ export async function POST(request: Request) {
|
|||||||
|
|
||||||
if (request.method === "POST") {
|
if (request.method === "POST") {
|
||||||
try {
|
try {
|
||||||
|
const file: any = formData.get("file");
|
||||||
|
console.log("ini file baru>", file);
|
||||||
|
|
||||||
|
// Resize ukuran
|
||||||
|
const imageBuffer = await file.arrayBuffer();
|
||||||
|
const resize = await sharp(imageBuffer).resize(2000).toBuffer();
|
||||||
|
|
||||||
|
// Convert buffer ke Blob
|
||||||
|
const blob = new Blob([resize], { type: file.type });
|
||||||
|
|
||||||
|
// Convert Blob ke File
|
||||||
|
const resizedFile = new File([blob], file.name, {
|
||||||
|
type: file.type,
|
||||||
|
lastModified: new Date().getTime(),
|
||||||
|
});
|
||||||
|
|
||||||
|
// Buat FormData baru
|
||||||
|
const newFormData = new FormData();
|
||||||
|
newFormData.append("file", resizedFile);
|
||||||
|
newFormData.append("dirId", formData.get("dirId") as string);
|
||||||
|
|
||||||
const res = await fetch("https://wibu-storage.wibudev.com/api/upload", {
|
const res = await fetch("https://wibu-storage.wibudev.com/api/upload", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: formData,
|
body: newFormData,
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${process.env.WS_APIKEY}`,
|
Authorization: `Bearer ${process.env.WS_APIKEY}`,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ export async function GET(request: Request) {
|
|||||||
where: {
|
where: {
|
||||||
id: userLoginId,
|
id: userLoginId,
|
||||||
},
|
},
|
||||||
select: {
|
include: {
|
||||||
Profile: {
|
Profile: {
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
|
|||||||
@@ -19,27 +19,30 @@ export type ITypeStatusNotifikasi =
|
|||||||
| "Menunggu"
|
| "Menunggu"
|
||||||
| "Gagal";
|
| "Gagal";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param kategoriApp | "JOB", "VOTING", "EVENT", "DONASI", "INVESTASI", "COLLABORATION", "FORUM"
|
* @param kategoriApp | "JOB", "VOTING", "EVENT", "DONASI", "INVESTASI", "COLLABORATION", "FORUM"
|
||||||
* @type string
|
* @type string
|
||||||
*/
|
*/
|
||||||
export type IRealtimeData = {
|
export type IRealtimeData = {
|
||||||
status?: ITypeStatusNotifikasi;
|
status?: ITypeStatusNotifikasi;
|
||||||
appId: string;
|
appId?: string;
|
||||||
userId: string;
|
userId: string;
|
||||||
pesan: string;
|
pesan?: string;
|
||||||
title: string;
|
title?: string;
|
||||||
kategoriApp:
|
kategoriApp?:
|
||||||
| "JOB"
|
| "JOB"
|
||||||
| "VOTING"
|
| "VOTING"
|
||||||
| "EVENT"
|
| "EVENT"
|
||||||
| "DONASI"
|
| "DONASI"
|
||||||
| "INVESTASI"
|
| "INVESTASI"
|
||||||
| "COLLABORATION"
|
| "COLLABORATION"
|
||||||
| "FORUM";
|
| "FORUM"
|
||||||
|
| "ACCESS"; // Untuk trigger akses user
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Access User
|
||||||
|
export const gs_access_user = atom<boolean>(false);
|
||||||
|
|
||||||
export const gs_realtimeData = atom<IRealtimeData | null>(null);
|
export const gs_realtimeData = atom<IRealtimeData | null>(null);
|
||||||
export const gs_admin_ntf = atom<number>(0);
|
export const gs_admin_ntf = atom<number>(0);
|
||||||
export const gs_user_ntf = atom<number>(0);
|
export const gs_user_ntf = atom<number>(0);
|
||||||
@@ -63,4 +66,4 @@ export const gs_donasiTriggerBeranda = atom<boolean>(false);
|
|||||||
|
|
||||||
// investasi
|
// investasi
|
||||||
export const gs_adminInvestasi_triggerReview = atom<boolean>(false);
|
export const gs_adminInvestasi_triggerReview = atom<boolean>(false);
|
||||||
export const gs_investasiTriggerBeranda = atom<boolean>(false);
|
export const gs_investasiTriggerBeranda = atom<boolean>(false);
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { useShallowEffect } from "@mantine/hooks";
|
|||||||
import { useAtom } from "jotai";
|
import { useAtom } from "jotai";
|
||||||
import { WibuRealtime } from "wibu-pkg";
|
import { WibuRealtime } from "wibu-pkg";
|
||||||
import {
|
import {
|
||||||
|
gs_access_user,
|
||||||
gs_admin_ntf,
|
gs_admin_ntf,
|
||||||
gs_adminDonasi_triggerReview,
|
gs_adminDonasi_triggerReview,
|
||||||
gs_adminEvent_triggerReview,
|
gs_adminEvent_triggerReview,
|
||||||
@@ -31,6 +32,9 @@ export type TypeNotification = {
|
|||||||
userId?: string;
|
userId?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Tambahkan flag global untuk mencegah inisialisasi ulang
|
||||||
|
let isWibuRealtimeInitialized = false;
|
||||||
|
|
||||||
export default function RealtimeProvider({
|
export default function RealtimeProvider({
|
||||||
userId,
|
userId,
|
||||||
WIBU_REALTIME_TOKEN,
|
WIBU_REALTIME_TOKEN,
|
||||||
@@ -42,6 +46,9 @@ export default function RealtimeProvider({
|
|||||||
const [newAdminNtf, setNewAdminNtf] = useAtom(gs_admin_ntf);
|
const [newAdminNtf, setNewAdminNtf] = useAtom(gs_admin_ntf);
|
||||||
const [newUserNtf, setNewUserNtf] = useAtom(gs_user_ntf);
|
const [newUserNtf, setNewUserNtf] = useAtom(gs_user_ntf);
|
||||||
|
|
||||||
|
// ACCESS USER
|
||||||
|
const [isAccessUser, setIsAccessUser] = useAtom(gs_access_user);
|
||||||
|
|
||||||
// JOB
|
// JOB
|
||||||
const [isTriggerJobBeranda, setIsTriggerJobBeranda] =
|
const [isTriggerJobBeranda, setIsTriggerJobBeranda] =
|
||||||
useAtom(gs_jobTiggerBeranda);
|
useAtom(gs_jobTiggerBeranda);
|
||||||
@@ -83,152 +90,168 @@ export default function RealtimeProvider({
|
|||||||
|
|
||||||
useShallowEffect(() => {
|
useShallowEffect(() => {
|
||||||
try {
|
try {
|
||||||
WibuRealtime.init({
|
if (!isWibuRealtimeInitialized) {
|
||||||
project: "hipmi",
|
WibuRealtime.init({
|
||||||
WIBU_REALTIME_TOKEN: WIBU_REALTIME_TOKEN,
|
project: "hipmi",
|
||||||
onData(data: TypeNotification) {
|
WIBU_REALTIME_TOKEN: WIBU_REALTIME_TOKEN,
|
||||||
if (
|
onData(data: TypeNotification) {
|
||||||
data.type == "notification" &&
|
// Notifikasi ke admin
|
||||||
data.pushNotificationTo == "ADMIN"
|
if (
|
||||||
) {
|
data.type == "notification" &&
|
||||||
setNewAdminNtf((e) => e + 1);
|
data.pushNotificationTo == "ADMIN"
|
||||||
}
|
) {
|
||||||
|
setNewAdminNtf((e) => e + 1);
|
||||||
|
}
|
||||||
|
|
||||||
// Notifikasi ke semua user , yang datanya di acc admin
|
// trigger access
|
||||||
if (
|
if (
|
||||||
data.type == "notification" &&
|
data.type == "trigger" &&
|
||||||
data.pushNotificationTo == "USER" &&
|
data.pushNotificationTo == "USER" &&
|
||||||
data.dataMessage?.userId == userId
|
data.dataMessage?.kategoriApp == "ACCESS" &&
|
||||||
) {
|
data.dataMessage?.userId == userId
|
||||||
setNewUserNtf((e) => e + 1);
|
) {
|
||||||
setDataRealtime(data.dataMessage as any);
|
setIsAccessUser(data.dataMessage.status as any);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------- JOB ------------------------- //
|
// Notifikasi ke semua user , yang datanya di acc admin
|
||||||
if (
|
if (
|
||||||
data.type == "trigger" &&
|
data.type == "notification" &&
|
||||||
data.pushNotificationTo == "ADMIN" &&
|
data.pushNotificationTo == "USER" &&
|
||||||
data.dataMessage?.kategoriApp == "JOB"
|
data.dataMessage?.userId == userId
|
||||||
) {
|
) {
|
||||||
setIsAdminJob_TriggerReview(true);
|
setNewUserNtf((e) => e + 1);
|
||||||
}
|
setDataRealtime(data.dataMessage as any);
|
||||||
|
}
|
||||||
|
|
||||||
if (
|
// ---------------------- JOB ------------------------- //
|
||||||
data.type == "trigger" &&
|
if (
|
||||||
data.pushNotificationTo == "USER" &&
|
data.type == "trigger" &&
|
||||||
data.dataMessage?.kategoriApp == "JOB" &&
|
data.pushNotificationTo == "ADMIN" &&
|
||||||
data.dataMessage.status == "Publish"
|
data.dataMessage?.kategoriApp == "JOB"
|
||||||
) {
|
) {
|
||||||
setIsTriggerJobBeranda(true);
|
setIsAdminJob_TriggerReview(true);
|
||||||
}
|
}
|
||||||
// ---------------------- JOB ------------------------- //
|
|
||||||
|
|
||||||
// ---------------------- EVENT ------------------------- //
|
if (
|
||||||
if (
|
data.type == "trigger" &&
|
||||||
data.type == "trigger" &&
|
data.pushNotificationTo == "USER" &&
|
||||||
data.pushNotificationTo == "ADMIN" &&
|
data.dataMessage?.kategoriApp == "JOB" &&
|
||||||
data.dataMessage?.kategoriApp == "EVENT"
|
data.dataMessage.status == "Publish"
|
||||||
) {
|
) {
|
||||||
setIsAdminEvent_TriggerReview(true);
|
setIsTriggerJobBeranda(true);
|
||||||
}
|
}
|
||||||
|
// ---------------------- JOB ------------------------- //
|
||||||
|
|
||||||
if (
|
// ---------------------- EVENT ------------------------- //
|
||||||
data.type == "trigger" &&
|
if (
|
||||||
data.pushNotificationTo == "USER" &&
|
data.type == "trigger" &&
|
||||||
data.dataMessage?.kategoriApp == "EVENT" &&
|
data.pushNotificationTo == "ADMIN" &&
|
||||||
data.dataMessage.status == "Publish"
|
data.dataMessage?.kategoriApp == "EVENT"
|
||||||
) {
|
) {
|
||||||
setIsTriggerEventBeranda(true);
|
setIsAdminEvent_TriggerReview(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
data.type == "notification" &&
|
data.type == "trigger" &&
|
||||||
data.pushNotificationTo == "USER" &&
|
data.pushNotificationTo == "USER" &&
|
||||||
data.dataMessage?.status == "Peserta Event" &&
|
data.dataMessage?.kategoriApp == "EVENT" &&
|
||||||
userId !== data.dataMessage?.userId
|
data.dataMessage.status == "Publish"
|
||||||
) {
|
) {
|
||||||
setNewUserNtf((e) => e + 1);
|
setIsTriggerEventBeranda(true);
|
||||||
}
|
}
|
||||||
// ---------------------- EVENT ------------------------- //
|
|
||||||
|
|
||||||
// ---------------------- VOTING ------------------------- //
|
if (
|
||||||
if (
|
data.type == "notification" &&
|
||||||
data.type == "trigger" &&
|
data.pushNotificationTo == "USER" &&
|
||||||
data.pushNotificationTo == "ADMIN" &&
|
data.dataMessage?.status == "Peserta Event" &&
|
||||||
data.dataMessage?.kategoriApp == "VOTING"
|
userId !== data.dataMessage?.userId
|
||||||
) {
|
) {
|
||||||
setIsAdminVoting_TriggerReview(true);
|
setNewUserNtf((e) => e + 1);
|
||||||
}
|
}
|
||||||
|
// ---------------------- EVENT ------------------------- //
|
||||||
|
|
||||||
if (
|
// ---------------------- VOTING ------------------------- //
|
||||||
data.type == "trigger" &&
|
if (
|
||||||
data.pushNotificationTo == "USER" &&
|
data.type == "trigger" &&
|
||||||
data.dataMessage?.kategoriApp == "VOTING" &&
|
data.pushNotificationTo == "ADMIN" &&
|
||||||
data.dataMessage.status == "Publish"
|
data.dataMessage?.kategoriApp == "VOTING"
|
||||||
) {
|
) {
|
||||||
setIsTriggerVotingBeranda(true);
|
setIsAdminVoting_TriggerReview(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
data.type == "notification" &&
|
data.type == "trigger" &&
|
||||||
data.pushNotificationTo == "USER" &&
|
data.pushNotificationTo == "USER" &&
|
||||||
data.dataMessage?.status == "Voting Masuk" &&
|
data.dataMessage?.kategoriApp == "VOTING" &&
|
||||||
userId !== data.dataMessage?.userId
|
data.dataMessage.status == "Publish"
|
||||||
) {
|
) {
|
||||||
setNewUserNtf((e) => e + 1);
|
setIsTriggerVotingBeranda(true);
|
||||||
}
|
}
|
||||||
// ---------------------- VOTING ------------------------- //
|
|
||||||
|
|
||||||
// ---------------------- DONASI ------------------------- //
|
if (
|
||||||
if (
|
data.type == "notification" &&
|
||||||
data.type == "trigger" &&
|
data.pushNotificationTo == "USER" &&
|
||||||
data.pushNotificationTo == "ADMIN" &&
|
data.dataMessage?.status == "Voting Masuk" &&
|
||||||
data.dataMessage?.kategoriApp == "DONASI"
|
userId !== data.dataMessage?.userId
|
||||||
) {
|
) {
|
||||||
setIsAdminDonasi_TriggerReview(true);
|
setNewUserNtf((e) => e + 1);
|
||||||
}
|
}
|
||||||
|
// ---------------------- VOTING ------------------------- //
|
||||||
|
|
||||||
if (
|
// ---------------------- DONASI ------------------------- //
|
||||||
data.type == "trigger" &&
|
if (
|
||||||
data.pushNotificationTo == "USER" &&
|
data.type == "trigger" &&
|
||||||
data.dataMessage?.kategoriApp == "DONASI" &&
|
data.pushNotificationTo == "ADMIN" &&
|
||||||
data.dataMessage.status == "Publish"
|
data.dataMessage?.kategoriApp == "DONASI"
|
||||||
) {
|
) {
|
||||||
setIsTriggerDonasiBeranda(true);
|
setIsAdminDonasi_TriggerReview(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (
|
if (
|
||||||
// data.type == "notification" &&
|
data.type == "trigger" &&
|
||||||
// data.pushNotificationTo == "ADMIN" &&
|
data.pushNotificationTo == "USER" &&
|
||||||
// data.dataMessage?.status == "Menunggu" &&
|
data.dataMessage?.kategoriApp == "DONASI" &&
|
||||||
// userId !== data.dataMessage?.userId
|
data.dataMessage.status == "Publish"
|
||||||
// ) {
|
) {
|
||||||
|
setIsTriggerDonasiBeranda(true);
|
||||||
|
}
|
||||||
|
|
||||||
// }
|
// if (
|
||||||
// ---------------------- DONASI ------------------------- //
|
// data.type == "notification" &&
|
||||||
|
// data.pushNotificationTo == "ADMIN" &&
|
||||||
|
// data.dataMessage?.status == "Menunggu" &&
|
||||||
|
// userId !== data.dataMessage?.userId
|
||||||
|
// ) {
|
||||||
|
|
||||||
// ---------------------- INVESTASI ------------------------- //
|
// }
|
||||||
|
// ---------------------- DONASI ------------------------- //
|
||||||
|
|
||||||
if (
|
// ---------------------- INVESTASI ------------------------- //
|
||||||
data.type == "trigger" &&
|
|
||||||
data.pushNotificationTo == "ADMIN" &&
|
|
||||||
data.dataMessage?.kategoriApp == "INVESTASI"
|
|
||||||
) {
|
|
||||||
setIsAdminInvestasi_TriggerReview(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
data.type == "trigger" &&
|
data.type == "trigger" &&
|
||||||
data.pushNotificationTo == "USER" &&
|
data.pushNotificationTo == "ADMIN" &&
|
||||||
data.dataMessage?.kategoriApp == "INVESTASI" &&
|
data.dataMessage?.kategoriApp == "INVESTASI"
|
||||||
data.dataMessage.status == "Publish"
|
) {
|
||||||
) {
|
setIsAdminInvestasi_TriggerReview(true);
|
||||||
setIsTriggerInvestasiBeranda(true);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// ---------------------- INVESTASI ------------------------- //
|
if (
|
||||||
},
|
data.type == "trigger" &&
|
||||||
});
|
data.pushNotificationTo == "USER" &&
|
||||||
|
data.dataMessage?.kategoriApp == "INVESTASI" &&
|
||||||
|
data.dataMessage.status == "Publish"
|
||||||
|
) {
|
||||||
|
setIsTriggerInvestasiBeranda(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------- INVESTASI ------------------------- //
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// Tandai bahwa WibuRealtime telah diinisialisasi
|
||||||
|
isWibuRealtimeInitialized = true;
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log("Error Realtime:", error);
|
console.log("Error Realtime:", error);
|
||||||
}
|
}
|
||||||
|
|||||||
52
src/app/zCoba/upload/fun_upload.ts
Normal file
52
src/app/zCoba/upload/fun_upload.ts
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
"use server";
|
||||||
|
|
||||||
|
import _ from "lodash";
|
||||||
|
// import { v4 } from "uuid";
|
||||||
|
import fs from "fs";
|
||||||
|
import sharp from "sharp";
|
||||||
|
|
||||||
|
export default async function fun_upload({
|
||||||
|
file,
|
||||||
|
dirId,
|
||||||
|
}: {
|
||||||
|
file: File;
|
||||||
|
dirId: string;
|
||||||
|
}) {
|
||||||
|
// const file: any = formData.get("file");
|
||||||
|
// const fName = file.name;
|
||||||
|
// const fileSize = file.size;
|
||||||
|
|
||||||
|
// // Convert ke KB
|
||||||
|
// const fileSizeInKB = fileSize / 1024;
|
||||||
|
|
||||||
|
// // Convert ke MB
|
||||||
|
// const fileSizeInMB = fileSize / (1024 * 1024);
|
||||||
|
|
||||||
|
// console.log(`Ukuran file dalam bytes: ${fileSize}`);
|
||||||
|
// console.log(`Ukuran file dalam KB: ${fileSizeInKB.toFixed(2)} KB`);
|
||||||
|
// console.log(`Ukuran file dalam MB: ${fileSizeInMB.toFixed(2)} MB`);
|
||||||
|
|
||||||
|
const imageBuffer = await file.arrayBuffer();
|
||||||
|
const resize = await sharp(imageBuffer).resize(2000).toBuffer();
|
||||||
|
|
||||||
|
const newFile = Buffer.from(resize);
|
||||||
|
console.log("file new",newFile);
|
||||||
|
// fs.writeFileSync(`./public/upload/${fName}`, upFolder as any);
|
||||||
|
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append("file", file);
|
||||||
|
formData.append("dirId", dirId);
|
||||||
|
|
||||||
|
// const upload = await fetch("/api/image/upload", {
|
||||||
|
// method: "POST",
|
||||||
|
// body: formData,
|
||||||
|
// });
|
||||||
|
|
||||||
|
// const res = await upload.json();
|
||||||
|
|
||||||
|
// if (upload.ok) {
|
||||||
|
// return { success: true, data: res.data, message: res.message };
|
||||||
|
// } else {
|
||||||
|
// return { success: false, data: {}, message: res.message };
|
||||||
|
// }
|
||||||
|
}
|
||||||
137
src/app/zCoba/upload/page.tsx
Normal file
137
src/app/zCoba/upload/page.tsx
Normal file
@@ -0,0 +1,137 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { MainColor } from "@/app_modules/_global/color";
|
||||||
|
import { ComponentGlobal_BoxUploadImage } from "@/app_modules/_global/component";
|
||||||
|
import { MAX_SIZE } from "@/app_modules/_global/lib";
|
||||||
|
import { PemberitahuanMaksimalFile } from "@/app_modules/_global/lib/max_size";
|
||||||
|
import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global";
|
||||||
|
import {
|
||||||
|
UIGlobal_LayoutHeaderTamplate,
|
||||||
|
UIGlobal_LayoutTamplate,
|
||||||
|
} from "@/app_modules/_global/ui";
|
||||||
|
import { clientLogger } from "@/util/clientLogger";
|
||||||
|
import {
|
||||||
|
AspectRatio,
|
||||||
|
Button,
|
||||||
|
Center,
|
||||||
|
FileButton,
|
||||||
|
Image,
|
||||||
|
Stack,
|
||||||
|
} from "@mantine/core";
|
||||||
|
import { IconImageInPicture, IconUpload } from "@tabler/icons-react";
|
||||||
|
import { useState } from "react";
|
||||||
|
import fun_upload from "./fun_upload";
|
||||||
|
import { funGlobal_UploadToStorage } from "@/app_modules/_global/fun";
|
||||||
|
|
||||||
|
export default function Page() {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<UIGlobal_LayoutTamplate
|
||||||
|
header={<UIGlobal_LayoutHeaderTamplate title="Upload" />}
|
||||||
|
>
|
||||||
|
<Upload />
|
||||||
|
</UIGlobal_LayoutTamplate>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function Upload() {
|
||||||
|
const [file, setFile] = useState<File | null>(null);
|
||||||
|
const [image, setImage] = useState<any | null>(null);
|
||||||
|
const [isLoading, setLoading] = useState(false);
|
||||||
|
|
||||||
|
async function onUpload() {
|
||||||
|
if (!file) return alert("File Kosong");
|
||||||
|
try {
|
||||||
|
setLoading(true);
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append("file", file as File);
|
||||||
|
|
||||||
|
const uploadPhoto = await funGlobal_UploadToStorage({
|
||||||
|
file: file,
|
||||||
|
dirId: "cm5ohsepe002bq4nlxeejhg7q",
|
||||||
|
});
|
||||||
|
|
||||||
|
if (uploadPhoto.success) {
|
||||||
|
setLoading(false);
|
||||||
|
alert("berhasil upload");
|
||||||
|
console.log("uploadPhoto", uploadPhoto);
|
||||||
|
} else {
|
||||||
|
setLoading(false);
|
||||||
|
console.log("gagal upload", uploadPhoto);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error upload img:", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Stack>
|
||||||
|
<ComponentGlobal_BoxUploadImage>
|
||||||
|
{image ? (
|
||||||
|
<AspectRatio ratio={1 / 1} mt={5} maw={300} mx={"auto"}>
|
||||||
|
<Image style={{ maxHeight: 250 }} alt="Avatar" src={image} />
|
||||||
|
</AspectRatio>
|
||||||
|
) : (
|
||||||
|
<Center h={"100%"}>
|
||||||
|
<IconImageInPicture size={50} />
|
||||||
|
</Center>
|
||||||
|
)}
|
||||||
|
</ComponentGlobal_BoxUploadImage>
|
||||||
|
|
||||||
|
<Center>
|
||||||
|
<FileButton
|
||||||
|
onChange={async (files: any | null) => {
|
||||||
|
try {
|
||||||
|
const buffer = URL.createObjectURL(
|
||||||
|
new Blob([new Uint8Array(await files.arrayBuffer())])
|
||||||
|
);
|
||||||
|
|
||||||
|
// if (files.size > MAX_SIZE) {
|
||||||
|
// ComponentGlobal_NotifikasiPeringatan(
|
||||||
|
// PemberitahuanMaksimalFile
|
||||||
|
// );
|
||||||
|
// return;
|
||||||
|
// } else {
|
||||||
|
|
||||||
|
// }
|
||||||
|
|
||||||
|
console.log("ini buffer", buffer);
|
||||||
|
|
||||||
|
setFile(files);
|
||||||
|
setImage(buffer);
|
||||||
|
} catch (error) {
|
||||||
|
clientLogger.error("Upload error:", error);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
accept="image/png,image/jpeg"
|
||||||
|
>
|
||||||
|
{(props) => (
|
||||||
|
<Button
|
||||||
|
{...props}
|
||||||
|
radius={"sm"}
|
||||||
|
leftIcon={<IconUpload />}
|
||||||
|
bg={MainColor.yellow}
|
||||||
|
color="yellow"
|
||||||
|
c={"black"}
|
||||||
|
>
|
||||||
|
Upload
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</FileButton>
|
||||||
|
</Center>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
loaderPosition="center"
|
||||||
|
loading={isLoading}
|
||||||
|
onClick={() => {
|
||||||
|
onUpload();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Simpan
|
||||||
|
</Button>
|
||||||
|
</Stack>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -256,6 +256,10 @@ function NewTableAdmin({
|
|||||||
search: isSearch,
|
search: isSearch,
|
||||||
page: isChoosePage,
|
page: isChoosePage,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
setDataAdmin(loadData.data);
|
setDataAdmin(loadData.data);
|
||||||
setNPage(loadData.nPage);
|
setNPage(loadData.nPage);
|
||||||
const loadDataUser = await adminDeveloper_funGetListAllUser({ page: 1 });
|
const loadDataUser = await adminDeveloper_funGetListAllUser({ page: 1 });
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
"use server";
|
"use server";
|
||||||
|
|
||||||
import prisma from "@/app/lib/prisma";
|
import prisma from "@/app/lib/prisma";
|
||||||
|
import backendLogger from "@/util/backendLogger";
|
||||||
import { revalidatePath } from "next/cache";
|
import { revalidatePath } from "next/cache";
|
||||||
|
import { headers } from "next/headers";
|
||||||
|
|
||||||
export default async function adminUserAccess_funEditAccess(
|
export default async function adminUserAccess_funEditAccess(
|
||||||
userId: string,
|
userId: string,
|
||||||
value: boolean
|
value: boolean,
|
||||||
|
nomor?: string
|
||||||
) {
|
) {
|
||||||
const updt = await prisma.user.update({
|
const updt = await prisma.user.update({
|
||||||
where: {
|
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" };
|
if (!updt) return { status: 400, message: "Update gagal" };
|
||||||
revalidatePath("/dev/admin/user-access");
|
revalidatePath("/dev/admin/user-access");
|
||||||
return { status: 200, message: "Update berhasil" };
|
return { status: 200, message: "Update berhasil" };
|
||||||
|
|||||||
@@ -20,6 +20,9 @@ import { IconSearch } from "@tabler/icons-react";
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import adminUserAccess_funEditAccess from "../fun/edit/fun_edit_access";
|
import adminUserAccess_funEditAccess from "../fun/edit/fun_edit_access";
|
||||||
import adminUserAccess_getListUser from "../fun/get/get_list_all_user";
|
import adminUserAccess_getListUser from "../fun/get/get_list_all_user";
|
||||||
|
import { WibuRealtime } from "wibu-pkg";
|
||||||
|
import { gs_access_user, IRealtimeData } from "@/app/lib/global_state";
|
||||||
|
import { useAtom } from "jotai";
|
||||||
|
|
||||||
export default function AdminUserAccess_View({ listUser }: { listUser: any }) {
|
export default function AdminUserAccess_View({ listUser }: { listUser: any }) {
|
||||||
const [data, setData] = useState<MODEL_USER[]>(listUser.data);
|
const [data, setData] = useState<MODEL_USER[]>(listUser.data);
|
||||||
@@ -30,11 +33,11 @@ export default function AdminUserAccess_View({ listUser }: { listUser: any }) {
|
|||||||
const [isLoadingDelete, setIsLoadingDelete] = useState(false);
|
const [isLoadingDelete, setIsLoadingDelete] = useState(false);
|
||||||
const [userId, setUserId] = useState("");
|
const [userId, setUserId] = useState("");
|
||||||
|
|
||||||
async function onAccess(id: string) {
|
async function onAccess(id: string, nomor: string) {
|
||||||
try {
|
try {
|
||||||
setUserId(id);
|
setUserId(id);
|
||||||
setIsLoadingAccess(true);
|
setIsLoadingAccess(true);
|
||||||
await adminUserAccess_funEditAccess(id, true).then(async (res) => {
|
await adminUserAccess_funEditAccess(id, true, nomor).then(async (res) => {
|
||||||
if (res.status === 200) {
|
if (res.status === 200) {
|
||||||
const value = await adminUserAccess_getListUser({
|
const value = await adminUserAccess_getListUser({
|
||||||
page: 1,
|
page: 1,
|
||||||
@@ -42,6 +45,19 @@ export default function AdminUserAccess_View({ listUser }: { listUser: any }) {
|
|||||||
});
|
});
|
||||||
setData(value.data as any);
|
setData(value.data as any);
|
||||||
setNPage(value.nPage);
|
setNPage(value.nPage);
|
||||||
|
|
||||||
|
const dataNotifikasi: IRealtimeData = {
|
||||||
|
status: true as any,
|
||||||
|
userId: id,
|
||||||
|
kategoriApp: "ACCESS",
|
||||||
|
};
|
||||||
|
|
||||||
|
WibuRealtime.setData({
|
||||||
|
type: "trigger",
|
||||||
|
pushNotificationTo: "USER",
|
||||||
|
dataMessage: dataNotifikasi,
|
||||||
|
});
|
||||||
|
|
||||||
ComponentGlobal_NotifikasiBerhasil(res.message);
|
ComponentGlobal_NotifikasiBerhasil(res.message);
|
||||||
} else {
|
} else {
|
||||||
ComponentGlobal_NotifikasiGagal(res.message);
|
ComponentGlobal_NotifikasiGagal(res.message);
|
||||||
@@ -118,7 +134,7 @@ export default function AdminUserAccess_View({ listUser }: { listUser: any }) {
|
|||||||
radius={"xl"}
|
radius={"xl"}
|
||||||
color="Green"
|
color="Green"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
onAccess(e.id);
|
onAccess(e.id, e.nomor);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Grand Access
|
Grand Access
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ export default function Login({ version }: { version: string }) {
|
|||||||
<Title order={3} c={MainColor.yellow}>
|
<Title order={3} c={MainColor.yellow}>
|
||||||
WELCOME TO
|
WELCOME TO
|
||||||
</Title>
|
</Title>
|
||||||
<Title c={MainColor.yellow}>HIPMI APPS</Title>
|
<Title order={2} c={MainColor.yellow}>HIPMI BADUNG APPS</Title>
|
||||||
</Stack>
|
</Stack>
|
||||||
|
|
||||||
<Stack w={300}>
|
<Stack w={300}>
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import { useRouter } from "next/navigation";
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { auth_funDeleteAktivasiKodeOtpByNomor } from "../fun/fun_edit_aktivasi_kode_otp_by_id";
|
import { auth_funDeleteAktivasiKodeOtpByNomor } from "../fun/fun_edit_aktivasi_kode_otp_by_id";
|
||||||
import Register_SkeletonView from "./skeleton";
|
import Register_SkeletonView from "./skeleton";
|
||||||
|
import { clientLogger } from "@/util/clientLogger";
|
||||||
|
|
||||||
export default function Register() {
|
export default function Register() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
@@ -70,28 +71,31 @@ export default function Register() {
|
|||||||
await auth_funDeleteAktivasiKodeOtpByNomor({
|
await auth_funDeleteAktivasiKodeOtpByNomor({
|
||||||
nomor: data.nomor,
|
nomor: data.nomor,
|
||||||
});
|
});
|
||||||
router.push("/dev/home", { scroll: false });
|
|
||||||
|
router.push("/waiting-room", { scroll: false });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res.status === 400) {
|
if (res.status === 400) {
|
||||||
|
setLoading(false);
|
||||||
ComponentGlobal_NotifikasiPeringatan(result.message);
|
ComponentGlobal_NotifikasiPeringatan(result.message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res.status === 405) {
|
if (res.status === 405) {
|
||||||
|
setLoading(false);
|
||||||
ComponentGlobal_NotifikasiPeringatan(result.message);
|
ComponentGlobal_NotifikasiPeringatan(result.message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res.status === 500) {
|
if (res.status === 500) {
|
||||||
|
setLoading(false);
|
||||||
ComponentGlobal_NotifikasiPeringatan(result.message);
|
ComponentGlobal_NotifikasiPeringatan(result.message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
|
||||||
} finally {
|
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
|
clientLogger.error("Error registrasi", error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -87,9 +87,6 @@ export default function Validasi() {
|
|||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
nomor: data.nomor,
|
nomor: data.nomor,
|
||||||
}),
|
}),
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const result = await res.json();
|
const result = await res.json();
|
||||||
@@ -100,6 +97,7 @@ export default function Validasi() {
|
|||||||
await auth_funDeleteAktivasiKodeOtpByNomor({
|
await auth_funDeleteAktivasiKodeOtpByNomor({
|
||||||
nomor: data.nomor,
|
nomor: data.nomor,
|
||||||
});
|
});
|
||||||
|
|
||||||
router.push(RouterHome.main_home, { scroll: false });
|
router.push(RouterHome.main_home, { scroll: false });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -110,30 +108,33 @@ export default function Validasi() {
|
|||||||
await auth_funDeleteAktivasiKodeOtpByNomor({
|
await auth_funDeleteAktivasiKodeOtpByNomor({
|
||||||
nomor: data.nomor,
|
nomor: data.nomor,
|
||||||
});
|
});
|
||||||
|
|
||||||
router.push(RouterAdminDashboard.splash_admin, { scroll: false });
|
router.push(RouterAdminDashboard.splash_admin, { scroll: false });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res.status === 404) {
|
if (res.status === 404) {
|
||||||
|
setLoading(false);
|
||||||
router.push("/register", { scroll: false });
|
router.push("/register", { scroll: false });
|
||||||
ComponentGlobal_NotifikasiBerhasil(result.message);
|
ComponentGlobal_NotifikasiBerhasil(result.message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res.status === 400) {
|
if (res.status === 400) {
|
||||||
|
setLoading(false);
|
||||||
ComponentGlobal_NotifikasiPeringatan(result.message);
|
ComponentGlobal_NotifikasiPeringatan(result.message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res.status == 500) {
|
if (res.status == 500) {
|
||||||
|
setLoading(false);
|
||||||
ComponentGlobal_NotifikasiGagal(result.message);
|
ComponentGlobal_NotifikasiGagal(result.message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
clientLogger.error("Error validasi:", error);
|
|
||||||
} finally {
|
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
clientLogger.error("Error validasi:", error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function onBack() {
|
async function onBack() {
|
||||||
|
|||||||
@@ -26,8 +26,8 @@ import { clientLogger } from "@/util/clientLogger";
|
|||||||
|
|
||||||
export default function BodyHome() {
|
export default function BodyHome() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [dataUser, setDataUser] = useState<any>({});
|
const [dataUser, setDataUser] = useState<any | null>(null);
|
||||||
const [dataJob, setDataJob] = useState<any[]>([]);
|
const [dataJob, setDataJob] = useState<any[] | null>(null);
|
||||||
const [loadingJob, setLoadingJob] = useState(true);
|
const [loadingJob, setLoadingJob] = useState(true);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
|
|
||||||
@@ -46,10 +46,12 @@ export default function BodyHome() {
|
|||||||
setDataUser(response.data);
|
setDataUser(response.data);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
clientLogger.error("Error get data user", error);
|
clientLogger.error("Error get data profile", error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async function getHomeJob() {
|
async function getHomeJob() {
|
||||||
try {
|
try {
|
||||||
setLoadingJob(true);
|
setLoadingJob(true);
|
||||||
@@ -70,19 +72,6 @@ export default function BodyHome() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Box>
|
<Box>
|
||||||
{/* <Paper
|
|
||||||
radius={"xl"}
|
|
||||||
h={150}
|
|
||||||
mb={"xs"}
|
|
||||||
style={{
|
|
||||||
borderRadius: "10px 10px 10px 10px",
|
|
||||||
border: `2px solid ${AccentColor.blue}`,
|
|
||||||
position: "relative",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
|
|
||||||
</Paper> */}
|
|
||||||
|
|
||||||
<Image
|
<Image
|
||||||
height={140}
|
height={140}
|
||||||
fit={"cover"}
|
fit={"cover"}
|
||||||
@@ -112,16 +101,11 @@ export default function BodyHome() {
|
|||||||
border: `2px solid ${AccentColor.blue}`,
|
border: `2px solid ${AccentColor.blue}`,
|
||||||
}}
|
}}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (
|
if (dataUser == null) {
|
||||||
dataUser.profile == undefined ||
|
|
||||||
dataUser?.profile == null ||
|
|
||||||
dataJob.length == undefined ||
|
|
||||||
dataJob.length == null
|
|
||||||
) {
|
|
||||||
return null;
|
return null;
|
||||||
} else if (
|
} else if (
|
||||||
dataUser.profile == undefined ||
|
Object.keys(dataUser).length == 0 ||
|
||||||
dataUser?.profile == null
|
dataJob?.length == null
|
||||||
) {
|
) {
|
||||||
router.push(RouterProfile.create, { scroll: false });
|
router.push(RouterProfile.create, { scroll: false });
|
||||||
} else {
|
} else {
|
||||||
@@ -163,16 +147,11 @@ export default function BodyHome() {
|
|||||||
>
|
>
|
||||||
<Stack
|
<Stack
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (
|
if (dataUser == null) {
|
||||||
dataUser.profile == undefined ||
|
|
||||||
dataUser?.profile == null ||
|
|
||||||
dataJob.length == undefined ||
|
|
||||||
dataJob.length == null
|
|
||||||
) {
|
|
||||||
return null;
|
return null;
|
||||||
} else if (
|
} else if (
|
||||||
dataUser.profile == undefined ||
|
Object.keys(dataUser).length == 0 ||
|
||||||
dataUser?.profile == null
|
dataJob?.length == null
|
||||||
) {
|
) {
|
||||||
router.push(RouterProfile.create, { scroll: false });
|
router.push(RouterProfile.create, { scroll: false });
|
||||||
} else {
|
} else {
|
||||||
@@ -229,7 +208,7 @@ export default function BodyHome() {
|
|||||||
<ComponentGlobal_IsEmptyData text="Tidak ada data" height={10} />
|
<ComponentGlobal_IsEmptyData text="Tidak ada data" height={10} />
|
||||||
) : (
|
) : (
|
||||||
<SimpleGrid cols={2} spacing="md">
|
<SimpleGrid cols={2} spacing="md">
|
||||||
{dataJob.map((e, i) => (
|
{dataJob?.map((e, i) => (
|
||||||
<Stack key={e.id}>
|
<Stack key={e.id}>
|
||||||
<Group spacing={"xs"}>
|
<Group spacing={"xs"}>
|
||||||
<Stack h={"100%"} align="center" justify="flex-start">
|
<Stack h={"100%"} align="center" justify="flex-start">
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ export default function FooterHome() {
|
|||||||
bottom={0}
|
bottom={0}
|
||||||
h={"9vh"}
|
h={"9vh"}
|
||||||
>
|
>
|
||||||
{dataUser?.profile === undefined || dataUser?.profile === null ? (
|
{dataUser == null ? (
|
||||||
<SimpleGrid cols={4}>
|
<SimpleGrid cols={4}>
|
||||||
{Array.from(new Array(4)).map((_, i) => (
|
{Array.from(new Array(4)).map((_, i) => (
|
||||||
<Center h={"9vh"} key={i}>
|
<Center h={"9vh"} key={i}>
|
||||||
@@ -69,15 +69,9 @@ export default function FooterHome() {
|
|||||||
align="center"
|
align="center"
|
||||||
spacing={0}
|
spacing={0}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (
|
if (dataUser == null) {
|
||||||
dataUser.profile === undefined ||
|
|
||||||
dataUser?.profile === null
|
|
||||||
) {
|
|
||||||
return null;
|
return null;
|
||||||
} else if (
|
} else if (Object.keys(dataUser).length === 0) {
|
||||||
dataUser.profile === undefined ||
|
|
||||||
dataUser?.profile === null
|
|
||||||
) {
|
|
||||||
router.push(RouterProfile.create, { scroll: false });
|
router.push(RouterProfile.create, { scroll: false });
|
||||||
} else {
|
} else {
|
||||||
if (e.link == "") {
|
if (e.link == "") {
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
import { atomWithStorage } from "jotai/utils";
|
import { atomWithStorage } from "jotai/utils";
|
||||||
|
import { atom } from "jotai";
|
||||||
|
|
||||||
export const gs_token = atomWithStorage<any | null>("gs_token", null);
|
export const gs_token = atomWithStorage<any | null>("gs_token", null);
|
||||||
@@ -68,7 +68,7 @@ export default function HomeViewNew() {
|
|||||||
<UIGlobal_LayoutHeaderTamplate
|
<UIGlobal_LayoutHeaderTamplate
|
||||||
title="HIPMI"
|
title="HIPMI"
|
||||||
customButtonLeft={
|
customButtonLeft={
|
||||||
dataUser?.profile == null ? (
|
dataUser == null ? (
|
||||||
<CustomSkeleton width={20} height={20} circle />
|
<CustomSkeleton width={20} height={20} circle />
|
||||||
) : (
|
) : (
|
||||||
<ActionIcon
|
<ActionIcon
|
||||||
@@ -91,7 +91,7 @@ export default function HomeViewNew() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
customButtonRight={
|
customButtonRight={
|
||||||
dataUser?.profile == null ? (
|
dataUser == null ? (
|
||||||
<CustomSkeleton width={20} height={20} circle />
|
<CustomSkeleton width={20} height={20} circle />
|
||||||
) : (
|
) : (
|
||||||
<ActionIcon
|
<ActionIcon
|
||||||
|
|||||||
@@ -3,13 +3,17 @@
|
|||||||
import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/_global/notif_global";
|
import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/_global/notif_global";
|
||||||
import { UIGlobal_LayoutDefault } from "@/app_modules/_global/ui";
|
import { UIGlobal_LayoutDefault } from "@/app_modules/_global/ui";
|
||||||
import { clientLogger } from "@/util/clientLogger";
|
import { clientLogger } from "@/util/clientLogger";
|
||||||
import { Skeleton, Stack, Text } from "@mantine/core";
|
import { Button, Skeleton, Stack, Text } from "@mantine/core";
|
||||||
import { useShallowEffect } from "@mantine/hooks";
|
import { useShallowEffect } from "@mantine/hooks";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { ComponentGlobal_CardStyles } from "../_global/component";
|
import { ComponentGlobal_CardStyles } from "../_global/component";
|
||||||
import { apiGetACtivationUser } from "../_global/lib/api_user";
|
import { apiGetACtivationUser } from "../_global/lib/api_user";
|
||||||
|
import { gs_access_user } from "@/app/lib/global_state";
|
||||||
|
import { useAtom } from "jotai";
|
||||||
|
import { MainColor } from "../_global/color";
|
||||||
|
import CustomSkeleton from "../components/CustomSkeleton";
|
||||||
|
|
||||||
export default function WaitingRoom_View({
|
export default function WaitingRoom_View({
|
||||||
userLoginId,
|
userLoginId,
|
||||||
@@ -18,6 +22,8 @@ export default function WaitingRoom_View({
|
|||||||
}) {
|
}) {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [isLoadingHome, setIsLoadingHome] = useState(false);
|
||||||
|
|
||||||
async function onClickLogout() {
|
async function onClickLogout() {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
const res = await fetch(`/api/auth/logout?id=${userLoginId}`, {
|
const res = await fetch(`/api/auth/logout?id=${userLoginId}`, {
|
||||||
@@ -31,7 +37,15 @@ export default function WaitingRoom_View({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const [data, setData] = useState<boolean | null>(null);
|
const [isAccess, setIsAccess] = useState<boolean | null>(null);
|
||||||
|
const [isAccessUser, setIsAccessUser] = useAtom(gs_access_user);
|
||||||
|
|
||||||
|
useShallowEffect(() => {
|
||||||
|
if (isAccessUser) {
|
||||||
|
setIsAccess(true);
|
||||||
|
setIsAccessUser(false);
|
||||||
|
}
|
||||||
|
}, [isAccessUser]);
|
||||||
|
|
||||||
useShallowEffect(() => {
|
useShallowEffect(() => {
|
||||||
onLoadData();
|
onLoadData();
|
||||||
@@ -41,7 +55,7 @@ export default function WaitingRoom_View({
|
|||||||
try {
|
try {
|
||||||
const respone = await apiGetACtivationUser();
|
const respone = await apiGetACtivationUser();
|
||||||
if (respone) {
|
if (respone) {
|
||||||
setData(respone.data);
|
setIsAccess(respone.data);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
clientLogger.error("Error get cookies user", error);
|
clientLogger.error("Error get cookies user", error);
|
||||||
@@ -53,11 +67,12 @@ export default function WaitingRoom_View({
|
|||||||
<UIGlobal_LayoutDefault>
|
<UIGlobal_LayoutDefault>
|
||||||
<Stack justify="cneter" h={"90vh"} mt={"xl"}>
|
<Stack justify="cneter" h={"90vh"} mt={"xl"}>
|
||||||
<ComponentGlobal_CardStyles>
|
<ComponentGlobal_CardStyles>
|
||||||
{_.isNull(data) ? (
|
{_.isNull(isAccess) ? (
|
||||||
<Stack>
|
<Stack align="center">
|
||||||
{Array.from(new Array(4)).map((e, i) => (
|
<CustomSkeleton height={20} width={"100%"} />
|
||||||
<Skeleton key={i} h={20} w={"100%"} />
|
<CustomSkeleton height={20} width={"70%"} />
|
||||||
))}
|
<CustomSkeleton height={20} width={"100%"} />
|
||||||
|
<CustomSkeleton height={20} width={"70%"} />
|
||||||
</Stack>
|
</Stack>
|
||||||
) : (
|
) : (
|
||||||
<Stack align="center">
|
<Stack align="center">
|
||||||
@@ -71,16 +86,28 @@ export default function WaitingRoom_View({
|
|||||||
Whatsapp setelah disetujui.
|
Whatsapp setelah disetujui.
|
||||||
</Text>
|
</Text>
|
||||||
</Stack>
|
</Stack>
|
||||||
|
{isAccess && (
|
||||||
{/* <Button
|
<Button
|
||||||
color="red"
|
color="yellow"
|
||||||
loaderPosition="center"
|
bg={MainColor.yellow}
|
||||||
loading={loading}
|
c={MainColor.darkblue}
|
||||||
radius={"xl"}
|
loaderPosition="center"
|
||||||
onClick={() => onClickLogout()}
|
loading={isLoadingHome}
|
||||||
>
|
radius={"xl"}
|
||||||
Keluar
|
onClick={() => {
|
||||||
</Button> */}
|
try {
|
||||||
|
setIsLoadingHome(true);
|
||||||
|
router.replace("/", { scroll: false });
|
||||||
|
} catch (error) {
|
||||||
|
clientLogger.error("Error button to home", error);
|
||||||
|
} finally {
|
||||||
|
setIsLoadingHome(false);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Home
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
</Stack>
|
</Stack>
|
||||||
)}
|
)}
|
||||||
</ComponentGlobal_CardStyles>
|
</ComponentGlobal_CardStyles>
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import { apies, pages } from "./lib/routes";
|
|||||||
type MiddlewareConfig = {
|
type MiddlewareConfig = {
|
||||||
apiPath: string;
|
apiPath: string;
|
||||||
loginPath: string;
|
loginPath: string;
|
||||||
|
// validasiPath: string;
|
||||||
|
// registarasiPath: string;
|
||||||
userPath: string;
|
userPath: string;
|
||||||
publicRoutes: string[];
|
publicRoutes: string[];
|
||||||
encodedKey: string;
|
encodedKey: string;
|
||||||
@@ -16,6 +18,8 @@ type MiddlewareConfig = {
|
|||||||
const middlewareConfig: MiddlewareConfig = {
|
const middlewareConfig: MiddlewareConfig = {
|
||||||
apiPath: "/api",
|
apiPath: "/api",
|
||||||
loginPath: "/login",
|
loginPath: "/login",
|
||||||
|
// validasiPath: "/validasi",
|
||||||
|
// registarasiPath: "/register",
|
||||||
userPath: "/dev/home",
|
userPath: "/dev/home",
|
||||||
publicRoutes: [
|
publicRoutes: [
|
||||||
// API
|
// API
|
||||||
@@ -45,6 +49,7 @@ const middlewareConfig: MiddlewareConfig = {
|
|||||||
"/auth/login",
|
"/auth/login",
|
||||||
"/auth/api/login",
|
"/auth/api/login",
|
||||||
"/waiting-room",
|
"/waiting-room",
|
||||||
|
"/zCoba/*",
|
||||||
|
|
||||||
// ASSETS
|
// ASSETS
|
||||||
"/aset/global/main_background.png",
|
"/aset/global/main_background.png",
|
||||||
@@ -61,6 +66,8 @@ export const middleware = async (req: NextRequest) => {
|
|||||||
apiPath,
|
apiPath,
|
||||||
encodedKey,
|
encodedKey,
|
||||||
loginPath,
|
loginPath,
|
||||||
|
// validasiPath,
|
||||||
|
// registarasiPath,
|
||||||
publicRoutes,
|
publicRoutes,
|
||||||
sessionKey,
|
sessionKey,
|
||||||
validationApiRoute,
|
validationApiRoute,
|
||||||
@@ -75,7 +82,12 @@ export const middleware = async (req: NextRequest) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Skip authentication for public routes
|
// Skip authentication for public routes
|
||||||
const isPublicRoute = [...publicRoutes, loginPath].some((route) => {
|
const isPublicRoute = [
|
||||||
|
...publicRoutes,
|
||||||
|
loginPath,
|
||||||
|
// validasiPath,
|
||||||
|
// registarasiPath,
|
||||||
|
].some((route) => {
|
||||||
const pattern = route.replace(/\*/g, ".*");
|
const pattern = route.replace(/\*/g, ".*");
|
||||||
return new RegExp(`^${pattern}$`).test(pathname);
|
return new RegExp(`^${pattern}$`).test(pathname);
|
||||||
});
|
});
|
||||||
@@ -88,7 +100,13 @@ export const middleware = async (req: NextRequest) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isPublicRoute && pathname !== loginPath) {
|
if (
|
||||||
|
isPublicRoute &&
|
||||||
|
pathname !== loginPath
|
||||||
|
// &&
|
||||||
|
// pathname !== validasiPath &&
|
||||||
|
// pathname !== registarasiPath
|
||||||
|
) {
|
||||||
return setCorsHeaders(NextResponse.next());
|
return setCorsHeaders(NextResponse.next());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,6 +114,7 @@ export const middleware = async (req: NextRequest) => {
|
|||||||
req.cookies.get(sessionKey)?.value ||
|
req.cookies.get(sessionKey)?.value ||
|
||||||
req.headers.get("Authorization")?.split(" ")[1];
|
req.headers.get("Authorization")?.split(" ")[1];
|
||||||
|
|
||||||
|
// ==================== Authentication: Login, Validasi, Registrasi ==================== //
|
||||||
// Token verification
|
// Token verification
|
||||||
const user = await verifyToken({ token, encodedKey });
|
const user = await verifyToken({ token, encodedKey });
|
||||||
|
|
||||||
@@ -107,10 +126,27 @@ export const middleware = async (req: NextRequest) => {
|
|||||||
return setCorsHeaders(NextResponse.next());
|
return setCorsHeaders(NextResponse.next());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// // Handle validation page access
|
||||||
|
// if (pathname === validasiPath) {
|
||||||
|
// if (user) {
|
||||||
|
// return setCorsHeaders(NextResponse.redirect(new URL(userPath, req.url)));
|
||||||
|
// }
|
||||||
|
// return setCorsHeaders(NextResponse.next());
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // Handle register page access
|
||||||
|
// if (pathname === registarasiPath) {
|
||||||
|
// if (user) {
|
||||||
|
// return setCorsHeaders(NextResponse.redirect(new URL(userPath, req.url)));
|
||||||
|
// }
|
||||||
|
// return setCorsHeaders(NextResponse.next());
|
||||||
|
// }
|
||||||
|
|
||||||
// Handle protected routes
|
// Handle protected routes
|
||||||
if (!user) {
|
if (!user) {
|
||||||
return setCorsHeaders(NextResponse.redirect(new URL(loginPath, req.url)));
|
return setCorsHeaders(NextResponse.redirect(new URL(loginPath, req.url)));
|
||||||
}
|
}
|
||||||
|
// ==================== Authentication: Login, Validasi, Registrasi ==================== //
|
||||||
|
|
||||||
if (pathname.startsWith("/dev")) {
|
if (pathname.startsWith("/dev")) {
|
||||||
const userValidate = await fetch(new URL("/api/user-validate", req.url), {
|
const userValidate = await fetch(new URL("/api/user-validate", req.url), {
|
||||||
|
|||||||
Reference in New Issue
Block a user