Fix layout realtime
This commit is contained in:
@@ -7,7 +7,7 @@
|
|||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "bun --bun run next dev --experimental-https",
|
"dev": "bun --bun run next dev --experimental-https",
|
||||||
"build": "bun --bun run next build",
|
"build": "NODE_OPTIONS='--max-old-space-size=2048' bun --bun run next build",
|
||||||
"start": "bun --bun run next start",
|
"start": "bun --bun run next start",
|
||||||
"lint": "bun --bun run next lint",
|
"lint": "bun --bun run next lint",
|
||||||
"ver": "bunx commit-and-tag-version -- --prerelease"
|
"ver": "bunx commit-and-tag-version -- --prerelease"
|
||||||
|
|||||||
41
src/app/api/user/route.ts
Normal file
41
src/app/api/user/route.ts
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
import { jwtVerify } from "jose";
|
||||||
|
import _ from "lodash";
|
||||||
|
import { cookies } from "next/headers";
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
|
||||||
|
export async function GET() {
|
||||||
|
// const data = await req.text();
|
||||||
|
// console.log(data);
|
||||||
|
const c = cookies().get(process.env.NEXT_PUBLIC_BASE_SESSION_KEY!);
|
||||||
|
|
||||||
|
if (!c || !c?.value || _.isEmpty(c?.value) || _.isUndefined(c?.value)) {
|
||||||
|
return NextResponse.json({ status: 401, message: "Unauthorized" });
|
||||||
|
}
|
||||||
|
|
||||||
|
const token = c.value;
|
||||||
|
const dataUser = await decrypt({
|
||||||
|
token: token,
|
||||||
|
encodedKey: process.env.NEXT_PUBLIC_BASE_TOKEN_KEY!,
|
||||||
|
});
|
||||||
|
|
||||||
|
return NextResponse.json({ status: 200, message: "OK", data: dataUser });
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,7 +11,7 @@ export default async function Layout({
|
|||||||
}: {
|
}: {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
}) {
|
}) {
|
||||||
const userLoginId = await funGetUserIdByToken();
|
// const userLoginId = await funGetUserIdByToken();
|
||||||
// const dataUser = await funGlobal_getUserById({
|
// const dataUser = await funGlobal_getUserById({
|
||||||
// userId: userLoginId as string,
|
// userId: userLoginId as string,
|
||||||
// });
|
// });
|
||||||
@@ -27,7 +27,7 @@ export default async function Layout({
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<RealtimeProvider
|
<RealtimeProvider
|
||||||
userLoginId={userLoginId as string}
|
userLoginId={"" as string}
|
||||||
WIBU_REALTIME_TOKEN={
|
WIBU_REALTIME_TOKEN={
|
||||||
ServerEnv.value?.NEXT_PUBLIC_WIBU_REALTIME_TOKEN as string
|
ServerEnv.value?.NEXT_PUBLIC_WIBU_REALTIME_TOKEN as string
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ import {
|
|||||||
gs_votingTiggerBeranda,
|
gs_votingTiggerBeranda,
|
||||||
IRealtimeData,
|
IRealtimeData,
|
||||||
} from "./global_state";
|
} from "./global_state";
|
||||||
|
import { useState } from "react";
|
||||||
|
import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global";
|
||||||
|
|
||||||
// const WIBU_REALTIME_TOKEN: string | undefined =
|
// const WIBU_REALTIME_TOKEN: string | undefined =
|
||||||
// process.env.NEXT_PUBLIC_WIBU_REALTIME_TOKEN;
|
// process.env.NEXT_PUBLIC_WIBU_REALTIME_TOKEN;
|
||||||
@@ -36,6 +38,7 @@ export default function RealtimeProvider({
|
|||||||
userLoginId: string;
|
userLoginId: string;
|
||||||
WIBU_REALTIME_TOKEN: string;
|
WIBU_REALTIME_TOKEN: string;
|
||||||
}) {
|
}) {
|
||||||
|
const [userId, setUserId] = useState("");
|
||||||
const [dataRealtime, setDataRealtime] = useAtom(gs_realtimeData);
|
const [dataRealtime, setDataRealtime] = useAtom(gs_realtimeData);
|
||||||
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);
|
||||||
@@ -72,138 +75,158 @@ export default function RealtimeProvider({
|
|||||||
);
|
);
|
||||||
|
|
||||||
useShallowEffect(() => {
|
useShallowEffect(() => {
|
||||||
// if (WIBU_REALTIME_TOKEN === undefined) return alert("gak dapet key");
|
onLoadUser({
|
||||||
try {
|
onSetUser(val: string) {
|
||||||
WibuRealtime.init({
|
|
||||||
project: "hipmi",
|
if (val !== "" || val !== undefined) {
|
||||||
WIBU_REALTIME_TOKEN: WIBU_REALTIME_TOKEN,
|
try {
|
||||||
onData(data: TypeNotification) {
|
WibuRealtime.init({
|
||||||
if (
|
project: "hipmi",
|
||||||
data.type == "notification" &&
|
WIBU_REALTIME_TOKEN: WIBU_REALTIME_TOKEN,
|
||||||
data.pushNotificationTo == "ADMIN"
|
onData(data: TypeNotification) {
|
||||||
) {
|
if (
|
||||||
setNewAdminNtf((e) => e + 1);
|
data.type == "notification" &&
|
||||||
|
data.pushNotificationTo == "ADMIN"
|
||||||
|
) {
|
||||||
|
setNewAdminNtf((e) => e + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Notifikasi ke semua user , yang datanya di acc admin
|
||||||
|
if (
|
||||||
|
data.type == "notification" &&
|
||||||
|
data.pushNotificationTo == "USER" &&
|
||||||
|
data.dataMessage?.userId == userId
|
||||||
|
) {
|
||||||
|
setNewUserNtf((e) => e + 1);
|
||||||
|
setDataRealtime(data.dataMessage as any);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------- JOB ------------------------- //
|
||||||
|
if (
|
||||||
|
data.type == "trigger" &&
|
||||||
|
data.pushNotificationTo == "ADMIN" &&
|
||||||
|
data.dataMessage?.kategoriApp == "JOB"
|
||||||
|
) {
|
||||||
|
setIsAdminJob_TriggerReview(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
data.type == "trigger" &&
|
||||||
|
data.pushNotificationTo == "USER" &&
|
||||||
|
data.dataMessage?.kategoriApp == "JOB" &&
|
||||||
|
data.dataMessage.status == "Publish"
|
||||||
|
) {
|
||||||
|
setIsTriggerJobBeranda(true);
|
||||||
|
}
|
||||||
|
// ---------------------- JOB ------------------------- //
|
||||||
|
|
||||||
|
// ---------------------- EVENT ------------------------- //
|
||||||
|
if (
|
||||||
|
data.type == "trigger" &&
|
||||||
|
data.pushNotificationTo == "ADMIN" &&
|
||||||
|
data.dataMessage?.kategoriApp == "EVENT"
|
||||||
|
) {
|
||||||
|
setIsAdminEvent_TriggerReview(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
data.type == "trigger" &&
|
||||||
|
data.pushNotificationTo == "USER" &&
|
||||||
|
data.dataMessage?.kategoriApp == "EVENT" &&
|
||||||
|
data.dataMessage.status == "Publish"
|
||||||
|
) {
|
||||||
|
setIsTriggerEventBeranda(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
data.type == "notification" &&
|
||||||
|
data.pushNotificationTo == "USER" &&
|
||||||
|
data.dataMessage?.status == "Peserta Event" &&
|
||||||
|
userId !== data.dataMessage?.userId
|
||||||
|
) {
|
||||||
|
setNewUserNtf((e) => e + 1);
|
||||||
|
}
|
||||||
|
// ---------------------- EVENT ------------------------- //
|
||||||
|
|
||||||
|
// ---------------------- VOTING ------------------------- //
|
||||||
|
if (
|
||||||
|
data.type == "trigger" &&
|
||||||
|
data.pushNotificationTo == "ADMIN" &&
|
||||||
|
data.dataMessage?.kategoriApp == "VOTING"
|
||||||
|
) {
|
||||||
|
setIsAdminVoting_TriggerReview(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
data.type == "trigger" &&
|
||||||
|
data.pushNotificationTo == "USER" &&
|
||||||
|
data.dataMessage?.kategoriApp == "VOTING" &&
|
||||||
|
data.dataMessage.status == "Publish"
|
||||||
|
) {
|
||||||
|
setIsTriggerVotingBeranda(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
data.type == "notification" &&
|
||||||
|
data.pushNotificationTo == "USER" &&
|
||||||
|
data.dataMessage?.status == "Voting Masuk" &&
|
||||||
|
userId !== data.dataMessage?.userId
|
||||||
|
) {
|
||||||
|
setNewUserNtf((e) => e + 1);
|
||||||
|
}
|
||||||
|
// ---------------------- VOTING ------------------------- //
|
||||||
|
|
||||||
|
// ---------------------- DONASI ------------------------- //
|
||||||
|
if (
|
||||||
|
data.type == "trigger" &&
|
||||||
|
data.pushNotificationTo == "ADMIN" &&
|
||||||
|
data.dataMessage?.kategoriApp == "DONASI"
|
||||||
|
) {
|
||||||
|
setIsAdminDonasi_TriggerReview(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
data.type == "trigger" &&
|
||||||
|
data.pushNotificationTo == "USER" &&
|
||||||
|
data.dataMessage?.kategoriApp == "DONASI" &&
|
||||||
|
data.dataMessage.status == "Publish"
|
||||||
|
) {
|
||||||
|
setIsTriggerDonasiBeranda(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// if (
|
||||||
|
// data.type == "notification" &&
|
||||||
|
// data.pushNotificationTo == "ADMIN" &&
|
||||||
|
// data.dataMessage?.status == "Menunggu" &&
|
||||||
|
// userLoginId !== data.dataMessage?.userId
|
||||||
|
// ) {
|
||||||
|
// console.log("yes");
|
||||||
|
// }
|
||||||
|
|
||||||
|
// ---------------------- DONASI ------------------------- //
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}, [setUserId]);
|
||||||
|
|
||||||
// Notifikasi ke semua user , yang datanya di acc admin
|
async function onLoadUser({
|
||||||
if (
|
onSetUser,
|
||||||
data.type == "notification" &&
|
}: {
|
||||||
data.pushNotificationTo == "USER" &&
|
onSetUser: (val: string) => void;
|
||||||
data.dataMessage?.userId == userLoginId
|
}) {
|
||||||
) {
|
const res = await fetch("/api/user", {
|
||||||
setNewUserNtf((e) => e + 1);
|
method: "GET",
|
||||||
setDataRealtime(data.dataMessage as any);
|
});
|
||||||
}
|
const result = await res.json();
|
||||||
|
onSetUser(result.data.id);
|
||||||
// ---------------------- JOB ------------------------- //
|
}
|
||||||
if (
|
|
||||||
data.type == "trigger" &&
|
|
||||||
data.pushNotificationTo == "ADMIN" &&
|
|
||||||
data.dataMessage?.kategoriApp == "JOB"
|
|
||||||
) {
|
|
||||||
setIsAdminJob_TriggerReview(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
data.type == "trigger" &&
|
|
||||||
data.pushNotificationTo == "USER" &&
|
|
||||||
data.dataMessage?.kategoriApp == "JOB" &&
|
|
||||||
data.dataMessage.status == "Publish"
|
|
||||||
) {
|
|
||||||
setIsTriggerJobBeranda(true);
|
|
||||||
}
|
|
||||||
// ---------------------- JOB ------------------------- //
|
|
||||||
|
|
||||||
// ---------------------- EVENT ------------------------- //
|
|
||||||
if (
|
|
||||||
data.type == "trigger" &&
|
|
||||||
data.pushNotificationTo == "ADMIN" &&
|
|
||||||
data.dataMessage?.kategoriApp == "EVENT"
|
|
||||||
) {
|
|
||||||
setIsAdminEvent_TriggerReview(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
data.type == "trigger" &&
|
|
||||||
data.pushNotificationTo == "USER" &&
|
|
||||||
data.dataMessage?.kategoriApp == "EVENT" &&
|
|
||||||
data.dataMessage.status == "Publish"
|
|
||||||
) {
|
|
||||||
setIsTriggerEventBeranda(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
data.type == "notification" &&
|
|
||||||
data.pushNotificationTo == "USER" &&
|
|
||||||
data.dataMessage?.status == "Peserta Event" &&
|
|
||||||
userLoginId !== data.dataMessage?.userId
|
|
||||||
) {
|
|
||||||
setNewUserNtf((e) => e + 1);
|
|
||||||
}
|
|
||||||
// ---------------------- EVENT ------------------------- //
|
|
||||||
|
|
||||||
// ---------------------- VOTING ------------------------- //
|
|
||||||
if (
|
|
||||||
data.type == "trigger" &&
|
|
||||||
data.pushNotificationTo == "ADMIN" &&
|
|
||||||
data.dataMessage?.kategoriApp == "VOTING"
|
|
||||||
) {
|
|
||||||
setIsAdminVoting_TriggerReview(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
data.type == "trigger" &&
|
|
||||||
data.pushNotificationTo == "USER" &&
|
|
||||||
data.dataMessage?.kategoriApp == "VOTING" &&
|
|
||||||
data.dataMessage.status == "Publish"
|
|
||||||
) {
|
|
||||||
setIsTriggerVotingBeranda(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
data.type == "notification" &&
|
|
||||||
data.pushNotificationTo == "USER" &&
|
|
||||||
data.dataMessage?.status == "Voting Masuk" &&
|
|
||||||
userLoginId !== data.dataMessage?.userId
|
|
||||||
) {
|
|
||||||
setNewUserNtf((e) => e + 1);
|
|
||||||
}
|
|
||||||
// ---------------------- VOTING ------------------------- //
|
|
||||||
|
|
||||||
// ---------------------- DONASI ------------------------- //
|
|
||||||
if (
|
|
||||||
data.type == "trigger" &&
|
|
||||||
data.pushNotificationTo == "ADMIN" &&
|
|
||||||
data.dataMessage?.kategoriApp == "DONASI"
|
|
||||||
) {
|
|
||||||
setIsAdminDonasi_TriggerReview(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
data.type == "trigger" &&
|
|
||||||
data.pushNotificationTo == "USER" &&
|
|
||||||
data.dataMessage?.kategoriApp == "DONASI" &&
|
|
||||||
data.dataMessage.status == "Publish"
|
|
||||||
) {
|
|
||||||
setIsTriggerDonasiBeranda(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// if (
|
|
||||||
// data.type == "notification" &&
|
|
||||||
// data.pushNotificationTo == "ADMIN" &&
|
|
||||||
// data.dataMessage?.status == "Menunggu" &&
|
|
||||||
// userLoginId !== data.dataMessage?.userId
|
|
||||||
// ) {
|
|
||||||
// console.log("yes");
|
|
||||||
// }
|
|
||||||
|
|
||||||
// ---------------------- DONASI ------------------------- //
|
|
||||||
},
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
console.log(error);
|
|
||||||
}
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,13 +7,16 @@ import { jwtVerify } from "jose";
|
|||||||
import { cookies } from "next/headers";
|
import { cookies } from "next/headers";
|
||||||
|
|
||||||
export async function funGetUserIdByToken() {
|
export async function funGetUserIdByToken() {
|
||||||
const c = cookies().get(process.env.NEXT_PUBLIC_BASE_SESSION_KEY!);
|
const SESSION_KEY = process.env.NEXT_PUBLIC_BASE_SESSION_KEY!;
|
||||||
|
// console.log("SESSION_KEY", SESSION_KEY);
|
||||||
|
const c = cookies().get("hipmi-key");
|
||||||
|
|
||||||
const cekUser = await decrypt({
|
const cekUser = await decrypt({
|
||||||
token: c?.value as string,
|
token: c?.value as string,
|
||||||
encodedKey: process.env.NEXT_PUBLIC_BASE_TOKEN_KEY!,
|
encodedKey: process.env.NEXT_PUBLIC_BASE_TOKEN_KEY!,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// console.log("userid" , cekUser?.id)
|
||||||
|
|
||||||
// const token = JSON.parse(
|
// const token = JSON.parse(
|
||||||
// await unsealData(c?.value as string, {
|
// await unsealData(c?.value as string, {
|
||||||
|
|||||||
@@ -74,9 +74,6 @@ export default function Ui_Konfirmasi({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isPresent === null) {
|
|
||||||
return <></>;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@@ -19,8 +19,10 @@ const middlewareConfig: MiddlewareConfig = {
|
|||||||
userPath: "/dev/home",
|
userPath: "/dev/home",
|
||||||
publicRoutes: [
|
publicRoutes: [
|
||||||
"/",
|
"/",
|
||||||
|
"/api/validation",
|
||||||
"/api/auth/*",
|
"/api/auth/*",
|
||||||
"/api/origin-url",
|
"/api/origin-url",
|
||||||
|
"/api/user",
|
||||||
"/login",
|
"/login",
|
||||||
"/register",
|
"/register",
|
||||||
"/validasi",
|
"/validasi",
|
||||||
|
|||||||
Reference in New Issue
Block a user