Fix prisma
Deskripsi: - Fun user id di buat baru dan mengambil dari cookies
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/** @type {import('next').NextConfig} */
|
||||
const nextConfig = {
|
||||
// reactStrictMode: false,
|
||||
reactStrictMode: false,
|
||||
experimental: {
|
||||
serverActions: true
|
||||
},
|
||||
|
||||
@@ -7,12 +7,9 @@ export default async function Layout({
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
}) {
|
||||
const userLoginId = await newFunGetUserId();
|
||||
|
||||
return (
|
||||
<>
|
||||
<RealtimeProvider
|
||||
userLoginId={userLoginId as string}
|
||||
WIBU_REALTIME_TOKEN={
|
||||
ServerEnv.value?.NEXT_PUBLIC_WIBU_REALTIME_TOKEN as string
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { jwtVerify } from "jose";
|
||||
"use server"
|
||||
|
||||
import _ from "lodash";
|
||||
import { cookies } from "next/headers";
|
||||
import { decrypt } from "../auth/_lib/decrypt";
|
||||
|
||||
export async function newFunGetUserId() {
|
||||
const c = cookies().get(process.env.NEXT_PUBLIC_BASE_SESSION_KEY!);
|
||||
@@ -17,22 +19,3 @@ export async function newFunGetUserId() {
|
||||
|
||||
return dataUser?.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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@ import {
|
||||
gs_votingTiggerBeranda,
|
||||
IRealtimeData,
|
||||
} from "./global_state";
|
||||
import { newFunGetUserId } from "./new_fun_user_id";
|
||||
import { useState } from "react";
|
||||
|
||||
// const WIBU_REALTIME_TOKEN: string | undefined =
|
||||
// process.env.NEXT_PUBLIC_WIBU_REALTIME_TOKEN;
|
||||
@@ -30,12 +32,11 @@ export type TypeNotification = {
|
||||
};
|
||||
|
||||
export default function RealtimeProvider({
|
||||
userLoginId,
|
||||
WIBU_REALTIME_TOKEN,
|
||||
}: {
|
||||
userLoginId: string;
|
||||
WIBU_REALTIME_TOKEN: string;
|
||||
}) {
|
||||
const [userLoginId, setUserLoginId] = useState("");
|
||||
const [dataRealtime, setDataRealtime] = useAtom(gs_realtimeData);
|
||||
const [newAdminNtf, setNewAdminNtf] = useAtom(gs_admin_ntf);
|
||||
const [newUserNtf, setNewUserNtf] = useAtom(gs_user_ntf);
|
||||
@@ -71,7 +72,14 @@ export default function RealtimeProvider({
|
||||
gs_donasiTriggerBeranda
|
||||
);
|
||||
|
||||
async function loadUserId() {
|
||||
const userId = await newFunGetUserId();
|
||||
|
||||
setUserLoginId(userId as string);
|
||||
}
|
||||
|
||||
useShallowEffect(() => {
|
||||
loadUserId();
|
||||
|
||||
try {
|
||||
WibuRealtime.init({
|
||||
|
||||
Reference in New Issue
Block a user