fix: get user cookies

Deskripsi:
- prefentif undefined value cookies

No Issues
This commit is contained in:
amel
2025-04-21 10:42:25 +08:00
parent a6e06a892a
commit be297ce6ce

View File

@@ -1,12 +1,14 @@
'use server' 'use server'
import { pwd_key_config, prisma } from "@/module/_global"; import { prisma, pwd_key_config } from "@/module/_global";
import { unsealData } from "iron-session"; import { unsealData } from "iron-session";
import { cookies } from "next/headers"; import { cookies } from "next/headers";
export default async function funGetUserByCookies() { export default async function funGetUserByCookies() {
const sessionCookie = cookies().get("sessionCookieSDM"); const sessionCookie = cookies().get("sessionCookieSDM")
const userId : any = await unsealData(sessionCookie!.value, {
if (sessionCookie != undefined) {
const userId: any = await unsealData(sessionCookie.value, {
password: pwd_key_config, password: pwd_key_config,
}); });
@@ -38,4 +40,17 @@ export default async function funGetUserByCookies() {
theme: warna, theme: warna,
showNotification: userId?.showNotification showNotification: userId?.showNotification
}; };
}else{
return {
id: undefined,
idUserRole: undefined,
name: undefined,
idVillage: undefined,
idGroup: undefined,
idPosition: undefined,
theme: undefined,
showNotification: undefined
};
}
} }