fix: get user cookies
Deskripsi: - prefentif undefined value cookies No Issues
This commit is contained in:
@@ -1,41 +1,56 @@
|
|||||||
'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, {
|
|
||||||
password: pwd_key_config,
|
|
||||||
});
|
|
||||||
|
|
||||||
const user = await prisma.user.findUnique({
|
if (sessionCookie != undefined) {
|
||||||
where: {
|
const userId: any = await unsealData(sessionCookie.value, {
|
||||||
id: userId.user ? String(userId.user) : String(userId),
|
password: pwd_key_config,
|
||||||
},
|
});
|
||||||
});
|
|
||||||
|
|
||||||
const village = await prisma.village.findUnique({
|
const user = await prisma.user.findUnique({
|
||||||
where: {
|
where: {
|
||||||
id: user?.idVillage
|
id: userId.user ? String(userId.user) : String(userId),
|
||||||
}
|
},
|
||||||
})
|
});
|
||||||
|
|
||||||
const warna = await prisma.colorTheme.findUnique({
|
const village = await prisma.village.findUnique({
|
||||||
where: {
|
where: {
|
||||||
id: String(village?.idTheme)
|
id: user?.idVillage
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const warna = await prisma.colorTheme.findUnique({
|
||||||
|
where: {
|
||||||
|
id: String(village?.idTheme)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: user?.id,
|
||||||
|
idUserRole: user?.idUserRole,
|
||||||
|
name: user?.name,
|
||||||
|
idVillage: user?.idVillage,
|
||||||
|
idGroup: user?.idGroup,
|
||||||
|
idPosition: user?.idPosition,
|
||||||
|
theme: warna,
|
||||||
|
showNotification: userId?.showNotification
|
||||||
|
};
|
||||||
|
}else{
|
||||||
|
return {
|
||||||
|
id: undefined,
|
||||||
|
idUserRole: undefined,
|
||||||
|
name: undefined,
|
||||||
|
idVillage: undefined,
|
||||||
|
idGroup: undefined,
|
||||||
|
idPosition: undefined,
|
||||||
|
theme: undefined,
|
||||||
|
showNotification: undefined
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
|
||||||
id: user?.id,
|
|
||||||
idUserRole: user?.idUserRole,
|
|
||||||
name: user?.name,
|
|
||||||
idVillage: user?.idVillage,
|
|
||||||
idGroup: user?.idGroup,
|
|
||||||
idPosition: user?.idPosition,
|
|
||||||
theme: warna,
|
|
||||||
showNotification: userId?.showNotification
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user