feat: tambah dependensi 'jose' versi 5.9.2 pada package.json
refactor: rapikan identasi dan buat field 'expires' opsional di model UserSession pada schema prisma chore: bersihkan import tidak terpakai di route login dan register API
This commit is contained in:
17
src/app_modules/_global/fun/get/fun_cek_token.ts
Normal file
17
src/app_modules/_global/fun/get/fun_cek_token.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
"use server";
|
||||
|
||||
import { prisma } from "@/app/lib";
|
||||
import _ from "lodash";
|
||||
import { cookies } from "next/headers";
|
||||
|
||||
export async function funCheckToken() {
|
||||
const c = cookies().get("ssn");
|
||||
const cekToken = await prisma.userSession.findFirst({
|
||||
where: {
|
||||
token: c?.value,
|
||||
},
|
||||
});
|
||||
|
||||
if (cekToken === null) return false;
|
||||
return true;
|
||||
}
|
||||
18
src/app_modules/_global/fun/get/fun_get_user_id_by_token.ts
Normal file
18
src/app_modules/_global/fun/get/fun_get_user_id_by_token.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
"use server";
|
||||
|
||||
import { cookies } from "next/headers";
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import { redirect } from "next/navigation";
|
||||
import { RouterAuth } from "@/app/lib/router_hipmi/router_auth";
|
||||
|
||||
export async function funGetUserIdByToken() {
|
||||
const c = cookies().get("ssn");
|
||||
const cekToken = await prisma.userSession.findFirst({
|
||||
where: {
|
||||
token: c?.value,
|
||||
},
|
||||
});
|
||||
|
||||
if (cekToken === null) return redirect(RouterAuth.login);
|
||||
return cekToken.userId;
|
||||
}
|
||||
@@ -1,5 +1,9 @@
|
||||
import { funCheckToken } from "./fun_cek_token";
|
||||
import { funGlobal_getNomorAdmin } from "./fun_get_nomor_admin";
|
||||
import { funGetUserIdByToken } from "./fun_get_user_id_by_token";
|
||||
import { funGlobal_getMasterKategoriApp } from "./fun_master_kategori_app";
|
||||
|
||||
export { funGlobal_getMasterKategoriApp };
|
||||
export { funGlobal_getNomorAdmin };
|
||||
export { funCheckToken };
|
||||
export { funGetUserIdByToken };
|
||||
|
||||
@@ -2,8 +2,10 @@
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import { RouterAdminColab } from "@/app/lib/router_admin/router_admin_colab";
|
||||
import { RouterAuth } from "@/app/lib/router_hipmi/router_auth";
|
||||
import { user_funGetOneUserId } from "@/app_modules/fun_global/get_user_token";
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
export default async function adminColab_funReportProjectById({
|
||||
colabId,
|
||||
@@ -13,6 +15,10 @@ export default async function adminColab_funReportProjectById({
|
||||
report: string;
|
||||
}) {
|
||||
const authorId = await user_funGetOneUserId();
|
||||
if (!authorId) {
|
||||
redirect(RouterAuth.login);
|
||||
// return { status: 400, message: "Gagal mendapatkan authorId" };
|
||||
}
|
||||
|
||||
const projectUpdate = await prisma.projectCollaboration.update({
|
||||
where: {
|
||||
|
||||
@@ -1,18 +1,32 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { cookies } from "next/headers";
|
||||
|
||||
export async function auth_Logout(kodeId: string) {
|
||||
cookies().set({
|
||||
name: "ssn",
|
||||
value: "",
|
||||
maxAge: 0,
|
||||
});
|
||||
|
||||
const c = cookies().get("ssn");
|
||||
if (c?.value !== "") return { status: 400, message: "Gagal Logout" };
|
||||
const userId = await funGetUserIdByToken();
|
||||
|
||||
try {
|
||||
const delToken = await prisma.userSession.delete({
|
||||
where: {
|
||||
userId: userId,
|
||||
},
|
||||
});
|
||||
|
||||
if (!delToken) return { status: 400, message: "Gagal Hapus User Session" };
|
||||
cookies().set({
|
||||
name: "ssn",
|
||||
value: "",
|
||||
maxAge: 0,
|
||||
expires: 0,
|
||||
});
|
||||
|
||||
return { status: 200, message: "Logout Berhasil" };
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
|
||||
// const del = await prisma.kodeOtp.delete({
|
||||
// where: {
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
"use server";
|
||||
|
||||
import { PwdCookies } from "@/app/lib";
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import { sealData } from "iron-session";
|
||||
import { cookies } from "next/headers";
|
||||
|
||||
|
||||
export async function Auth_funRegister(data: any) {
|
||||
|
||||
export async function Auth_funRegister({
|
||||
data,
|
||||
HIPMI_PWD,
|
||||
}: {
|
||||
data: any;
|
||||
HIPMI_PWD: string;
|
||||
}) {
|
||||
const cekUsername = await prisma.user.findUnique({
|
||||
where: {
|
||||
username: data.username,
|
||||
@@ -28,21 +31,31 @@ export async function Auth_funRegister(data: any) {
|
||||
});
|
||||
if (!create) return { status: 400, message: "Gagal Mendaftar" };
|
||||
|
||||
const seal = await sealData(
|
||||
const sealToken = await sealData(
|
||||
JSON.stringify({
|
||||
id: create.id,
|
||||
username: create.username,
|
||||
}),
|
||||
{
|
||||
password: PwdCookies
|
||||
password: HIPMI_PWD,
|
||||
}
|
||||
);
|
||||
|
||||
cookies().set({
|
||||
name: "ssn",
|
||||
value: seal,
|
||||
maxAge: 60 * 60 * 24 * 7,
|
||||
value: sealToken,
|
||||
// maxAge: 60 * 60 * 24 * 7,
|
||||
});
|
||||
|
||||
const createUserSession = await prisma.userSession.create({
|
||||
data: {
|
||||
token: sealToken,
|
||||
userId: create.id,
|
||||
},
|
||||
});
|
||||
|
||||
if (!createUserSession)
|
||||
return { status: 400, message: "Gagal Membuat User Session" };
|
||||
|
||||
return { status: 200, message: "Berhasil Mendaftar" };
|
||||
}
|
||||
|
||||
@@ -1,15 +1,19 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import { sealData } from "iron-session";
|
||||
import { cookies } from "next/headers";
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { RouterHome } from "@/app/lib/router_hipmi/router_home";
|
||||
import { PwdCookies } from "@/app/lib";
|
||||
import { sealData, unsealData } from "iron-session";
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { cookies } from "next/headers";
|
||||
|
||||
|
||||
export async function auth_funValidasi(nomor: string) {
|
||||
const cek = await prisma.user.findUnique({
|
||||
export async function auth_funValidasi({
|
||||
nomor,
|
||||
HIPMI_PWD,
|
||||
}: {
|
||||
nomor: string;
|
||||
HIPMI_PWD: string;
|
||||
}) {
|
||||
const cekUser = await prisma.user.findUnique({
|
||||
where: {
|
||||
nomor: nomor,
|
||||
},
|
||||
@@ -21,30 +25,44 @@ export async function auth_funValidasi(nomor: string) {
|
||||
},
|
||||
});
|
||||
|
||||
if (cek === null) return { status: 400, message: "Nomor Belum Terdaftar" };
|
||||
if (cek) {
|
||||
const res = await sealData(
|
||||
JSON.stringify({
|
||||
id: cek.id,
|
||||
username: cek.username,
|
||||
}),
|
||||
{
|
||||
password: PwdCookies,
|
||||
}
|
||||
);
|
||||
if (cekUser === null) return { status: 400, message: "Nomor Belum Terdaftar" };
|
||||
|
||||
cookies().set({
|
||||
name: "ssn",
|
||||
value: res,
|
||||
maxAge: 60 * 60 * 24 * 30,
|
||||
const sealToken = await sealData(
|
||||
JSON.stringify({
|
||||
id: cekUser.id,
|
||||
username: cekUser.username,
|
||||
}),
|
||||
{
|
||||
password: HIPMI_PWD,
|
||||
}
|
||||
);
|
||||
|
||||
cookies().set({
|
||||
name: "ssn",
|
||||
value: sealToken,
|
||||
// maxAge: 60 * 60 * 24 * 30,
|
||||
// expires: 60 * 60 * 24 * 30,
|
||||
});
|
||||
|
||||
try {
|
||||
const createUserSession = await prisma.userSession.create({
|
||||
data: {
|
||||
token: sealToken,
|
||||
userId: cekUser.id,
|
||||
},
|
||||
});
|
||||
|
||||
if (!createUserSession)
|
||||
return { status: 401, message: "Gagal Membuat User Session" };
|
||||
|
||||
revalidatePath(RouterHome.main_home);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
|
||||
return {
|
||||
status: 200,
|
||||
message: "Nomor Terverifikasi",
|
||||
role: cek.masterUserRoleId,
|
||||
role: cekUser.masterUserRoleId,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -6,8 +6,6 @@ import {
|
||||
MainColor,
|
||||
} from "@/app_modules/_global/color/color_pallet";
|
||||
import ComponentGlobal_ErrorInput from "@/app_modules/_global/component/error_input";
|
||||
import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/_global/notif_global/notifikasi_berhasil";
|
||||
import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global/notifikasi_peringatan";
|
||||
import { auth_funLogin } from "@/app_modules/auth/fun/fun_login";
|
||||
import {
|
||||
BackgroundImage,
|
||||
@@ -17,18 +15,20 @@ import {
|
||||
Text,
|
||||
Title,
|
||||
} from "@mantine/core";
|
||||
import { useFocusTrap } from "@mantine/hooks";
|
||||
import { useAtom } from "jotai";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { PhoneInput } from "react-international-phone";
|
||||
import "react-international-phone/style.css";
|
||||
import { gs_kodeId } from "../state/state";
|
||||
import {
|
||||
ComponentGlobal_NotifikasiBerhasil,
|
||||
ComponentGlobal_NotifikasiPeringatan,
|
||||
} from "@/app_modules/_global/notif_global";
|
||||
|
||||
export default function Login() {
|
||||
const router = useRouter();
|
||||
const [kodeId, setKodeId] = useAtom(gs_kodeId);
|
||||
const focusTrapRef = useFocusTrap();
|
||||
const [phone, setPhone] = useState("");
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [isError, setError] = useState(false);
|
||||
@@ -38,16 +38,15 @@ export default function Login() {
|
||||
|
||||
if (nomorHp.length <= 4) return setError(true);
|
||||
|
||||
await auth_funLogin(nomorHp).then((res) => {
|
||||
if (res.status === 200) {
|
||||
setLoading(true);
|
||||
ComponentGlobal_NotifikasiBerhasil(res.message, 2000);
|
||||
setKodeId(res.kodeOtpId);
|
||||
router.push(RouterAuth.validasi + res.kodeOtpId);
|
||||
} else {
|
||||
ComponentGlobal_NotifikasiPeringatan(res.message);
|
||||
}
|
||||
});
|
||||
const res = await auth_funLogin(nomorHp);
|
||||
if (res.status === 200) {
|
||||
setLoading(true);
|
||||
ComponentGlobal_NotifikasiBerhasil(res.message, 2000);
|
||||
setKodeId(res.kodeOtpId);
|
||||
router.push(RouterAuth.validasi + res.kodeOtpId);
|
||||
} else {
|
||||
ComponentGlobal_NotifikasiPeringatan(res.message);
|
||||
}
|
||||
|
||||
// await fetch(ApiHipmi.login, {
|
||||
// method: "POST",
|
||||
|
||||
@@ -4,12 +4,7 @@ import { Warna } from "@/app/lib/warna";
|
||||
import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/_global/notif_global/notifikasi_berhasil";
|
||||
import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global/notifikasi_peringatan";
|
||||
import UIGlobal_Modal from "@/app_modules/_global/ui/ui_modal";
|
||||
import {
|
||||
ActionIcon,
|
||||
Button,
|
||||
Stack,
|
||||
Text
|
||||
} from "@mantine/core";
|
||||
import { ActionIcon, Button, Stack, Text } from "@mantine/core";
|
||||
import { IconLogout } from "@tabler/icons-react";
|
||||
import { useAtom } from "jotai";
|
||||
import { useRouter } from "next/navigation";
|
||||
@@ -24,9 +19,6 @@ export default function Component_Logout() {
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
async function onClickLogout() {
|
||||
// await auth_Logout(kodeId).then((res) => {
|
||||
// ComponentGlobal_NotifikasiBerhasil("Berhasil Logout");
|
||||
// });
|
||||
await auth_Logout(kodeId).then((res) => {
|
||||
if (res.status === 200) {
|
||||
ComponentGlobal_NotifikasiBerhasil(res.message);
|
||||
|
||||
@@ -15,17 +15,16 @@ import {
|
||||
Stack,
|
||||
Text,
|
||||
TextInput,
|
||||
Title
|
||||
Title,
|
||||
} from "@mantine/core";
|
||||
import { useFocusTrap } from "@mantine/hooks";
|
||||
import {
|
||||
IconUserCircle
|
||||
} from "@tabler/icons-react";
|
||||
import { IconUserCircle } from "@tabler/icons-react";
|
||||
import _ from "lodash";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { auth_funDeleteAktivasiKodeOtpById } from "../fun/fun_edit_aktivasi_kode_otp_by_id";
|
||||
import { Auth_funRegister } from "../fun/fun_register";
|
||||
import { GlobalEnv } from "@/app/lib/token";
|
||||
|
||||
export default function Register({ dataOtp }: { dataOtp: any }) {
|
||||
const router = useRouter();
|
||||
@@ -40,7 +39,6 @@ export default function Register({ dataOtp }: { dataOtp: any }) {
|
||||
username: value,
|
||||
nomor: nomor,
|
||||
};
|
||||
// console.log(body);
|
||||
|
||||
if (body.username === "") {
|
||||
setIsValue(true);
|
||||
@@ -49,7 +47,7 @@ export default function Register({ dataOtp }: { dataOtp: any }) {
|
||||
if (body.username.length < 5) return null;
|
||||
if (_.values(body.username).includes(" ")) return null;
|
||||
|
||||
const res = await Auth_funRegister(body)
|
||||
const res = await Auth_funRegister({data: body, HIPMI_PWD: GlobalEnv.value?.WIBU_PWD as string});
|
||||
if (res.status === 200) {
|
||||
await auth_funDeleteAktivasiKodeOtpById(dataOtp.id).then((val) => {
|
||||
if (val.status === 200) {
|
||||
@@ -67,16 +65,12 @@ export default function Register({ dataOtp }: { dataOtp: any }) {
|
||||
|
||||
return (
|
||||
<>
|
||||
{/* <pre>{JSON.stringify(dataOtp,null,2)}</pre> */}
|
||||
<BackgroundImage
|
||||
src={"/aset/global/main_background.png"}
|
||||
h={"100vh"}
|
||||
// pos={"static"}
|
||||
>
|
||||
<BackgroundImage src={"/aset/global/main_background.png"} h={"100vh"}>
|
||||
<Center h={"100vh"}>
|
||||
<Stack h={"100%"} align="center" justify="center" spacing={70}>
|
||||
<Title order={2} c={MainColor.yellow}>
|
||||
REGISTRASI
|
||||
{GlobalEnv.value?.DATABASE_URL}
|
||||
</Title>
|
||||
|
||||
<IconUserCircle size={100} color="white" />
|
||||
|
||||
@@ -26,6 +26,7 @@ import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { auth_funDeleteAktivasiKodeOtpById } from "../fun/fun_edit_aktivasi_kode_otp_by_id";
|
||||
import { auth_funValidasi } from "../fun/fun_validasi";
|
||||
import { GlobalEnv } from "@/app/lib/token";
|
||||
|
||||
export default function Validasi({ dataOtp }: { dataOtp: any }) {
|
||||
const router = useRouter();
|
||||
@@ -41,9 +42,11 @@ export default function Validasi({ dataOtp }: { dataOtp: any }) {
|
||||
if (code != inputCode)
|
||||
return ComponentGlobal_NotifikasiPeringatan("Kode Salah");
|
||||
|
||||
const res = await auth_funValidasi(nomor);
|
||||
const res = await auth_funValidasi({
|
||||
nomor: nomor,
|
||||
HIPMI_PWD: GlobalEnv.value?.WIBU_PWD as string,
|
||||
});
|
||||
if (res.status === 200) {
|
||||
|
||||
const resAktivasi = await auth_funDeleteAktivasiKodeOtpById(dataOtp.id);
|
||||
if (resAktivasi.status === 200) {
|
||||
if (res.role === "1") {
|
||||
@@ -51,12 +54,13 @@ export default function Validasi({ dataOtp }: { dataOtp: any }) {
|
||||
setLoading(true);
|
||||
router.push(RouterHome.main_home, { scroll: false });
|
||||
} else {
|
||||
router.push(RouterAdminDashboard.splash_admin);
|
||||
ComponentGlobal_NotifikasiBerhasil("Admin Logged in");
|
||||
setLoading(true);
|
||||
router.push(RouterAdminDashboard.splash_admin, { scroll: false });
|
||||
}
|
||||
} else {
|
||||
ComponentGlobal_NotifikasiPeringatan(resAktivasi.message);
|
||||
}
|
||||
|
||||
} else {
|
||||
ComponentGlobal_NotifikasiBerhasil(res.message);
|
||||
router.push(RouterAuth.register + dataOtp.id, { scroll: false });
|
||||
|
||||
5
src/app_modules/check_cookies/index.ts
Normal file
5
src/app_modules/check_cookies/index.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import { CheckCookies_UiLayout } from "./layout_cek_cookies";
|
||||
import { CheckCookies_UiView } from "./ui_check_cookies";
|
||||
|
||||
export { CheckCookies_UiView };
|
||||
export { CheckCookies_UiLayout };
|
||||
27
src/app_modules/check_cookies/layout_cek_cookies.tsx
Normal file
27
src/app_modules/check_cookies/layout_cek_cookies.tsx
Normal file
@@ -0,0 +1,27 @@
|
||||
"use client";
|
||||
|
||||
import { RouterAuth } from "@/app/lib/router_hipmi/router_auth";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
import { useRouter } from "next/navigation";
|
||||
|
||||
export function CheckCookies_UiLayout({
|
||||
children,
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
}) {
|
||||
const router = useRouter();
|
||||
|
||||
useShallowEffect(() => {
|
||||
onCheckCookies();
|
||||
}, []);
|
||||
|
||||
async function onCheckCookies() {
|
||||
const cek = await fetch("/api/check-cookies");
|
||||
const result = await cek.json();
|
||||
if (result.success === false) {
|
||||
router.push(RouterAuth.login);
|
||||
}
|
||||
}
|
||||
|
||||
return <>{children}</>;
|
||||
}
|
||||
23
src/app_modules/check_cookies/ui_check_cookies.tsx
Normal file
23
src/app_modules/check_cookies/ui_check_cookies.tsx
Normal file
@@ -0,0 +1,23 @@
|
||||
"use client";
|
||||
|
||||
import { Button, Center } from "@mantine/core";
|
||||
import { UIGlobal_LayoutTamplate } from "../_global/ui";
|
||||
import { RouterAuth } from "@/app/lib/router_hipmi/router_auth";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
|
||||
export function CheckCookies_UiView() {
|
||||
const router = useRouter();
|
||||
|
||||
return (
|
||||
<>
|
||||
<UIGlobal_LayoutTamplate>
|
||||
<Center h={"80vh"}>
|
||||
<Button radius={"xl"} onClick={() => router.push(RouterAuth.login)}>
|
||||
Kembali ke Halaman Login
|
||||
</Button>
|
||||
</Center>
|
||||
</UIGlobal_LayoutTamplate>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import { RouterAuth } from "@/app/lib/router_hipmi/router_auth";
|
||||
import { user_funGetOneUserId } from "@/app_modules/fun_global/get_user_token";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
export default async function colab_funCreateRoomChat(
|
||||
nameRoom: string,
|
||||
@@ -9,6 +11,10 @@ export default async function colab_funCreateRoomChat(
|
||||
colabId: string
|
||||
) {
|
||||
const authorId = await user_funGetOneUserId();
|
||||
if (!authorId) {
|
||||
redirect(RouterAuth.login);
|
||||
// return { status: 400, message: "Gagal mendapatkan authorId" };
|
||||
}
|
||||
|
||||
const createRoom = await prisma.projectCollaboration_RoomChat.create({
|
||||
data: {
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import { RouterAuth } from "@/app/lib/router_hipmi/router_auth";
|
||||
import { user_funGetOneUserId } from "@/app_modules/fun_global/get_user_token";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
export default async function colab_CekNotifikasi() {
|
||||
const authorId = await user_funGetOneUserId();
|
||||
if (!authorId) {
|
||||
redirect(RouterAuth.login);
|
||||
// return { status: 400, message: "Gagal mendapatkan authorId" };
|
||||
}
|
||||
|
||||
const cekNotif = await prisma.projectCollaboration_Notifikasi.findMany({
|
||||
where: {
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import { RouterAuth } from "@/app/lib/router_hipmi/router_auth";
|
||||
import { user_funGetOneUserId } from "@/app_modules/fun_global/get_user_token";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
export default async function colab_getListNotifikasiByUserId() {
|
||||
const authorId = await user_funGetOneUserId();
|
||||
if (!authorId) {
|
||||
redirect(RouterAuth.login);
|
||||
// return { status: 400, message: "Gagal mendapatkan authorId" };
|
||||
}
|
||||
|
||||
const get = await prisma.projectCollaboration_Notifikasi.findMany({
|
||||
orderBy: {
|
||||
|
||||
@@ -1,10 +1,20 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import { RouterAuth } from "@/app/lib/router_hipmi/router_auth";
|
||||
import { user_funGetOneUserId } from "@/app_modules/fun_global/get_user_token";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
export default async function colab_getListRoomChatByAuthorId({page}: {page: number}) {
|
||||
const userLoginId = await user_funGetOneUserId();
|
||||
export default async function colab_getListRoomChatByAuthorId({
|
||||
page,
|
||||
}: {
|
||||
page: number;
|
||||
}) {
|
||||
const authorId = await user_funGetOneUserId();
|
||||
if (!authorId) {
|
||||
redirect(RouterAuth.login);
|
||||
// return { status: 400, message: "Gagal mendapatkan authorId" };
|
||||
}
|
||||
const takeData = 10;
|
||||
const skipData = page * takeData - takeData;
|
||||
|
||||
@@ -15,7 +25,7 @@ export default async function colab_getListRoomChatByAuthorId({page}: {page: num
|
||||
createdAt: "desc",
|
||||
},
|
||||
where: {
|
||||
userId: userLoginId,
|
||||
userId: authorId,
|
||||
},
|
||||
select: {
|
||||
ProjectCollaboration_RoomChat: {
|
||||
@@ -36,5 +46,4 @@ export default async function colab_getListRoomChatByAuthorId({page}: {page: num
|
||||
// console.log(listRoom);
|
||||
|
||||
return listRoom;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,24 +1,27 @@
|
||||
"use server";
|
||||
|
||||
import { cookies } from "next/headers";
|
||||
import { unsealData } from "iron-session";
|
||||
import { redirect } from "next/navigation";
|
||||
import { RouterAuth } from "@/app/lib/router_hipmi/router_auth";
|
||||
import { ServerEnv } from "@/app/lib/server_env";
|
||||
import { unsealData } from "iron-session";
|
||||
import _ from "lodash";
|
||||
import { PwdCookies } from "@/app/lib";
|
||||
import { cookies } from "next/headers";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
export async function user_funGetOneUserId(): Promise<string | null> {
|
||||
try {
|
||||
const kukis = cookies();
|
||||
const c = kukis.get("ssn");
|
||||
if (!c || !c?.value || _.isEmpty(c?.value) || _.isUndefined(c?.value))
|
||||
return redirect(RouterAuth.login);
|
||||
|
||||
export async function user_funGetOneUserId() {
|
||||
const kukis = cookies();
|
||||
const c = kukis.get("ssn");
|
||||
if (!c || !c?.value || _.isEmpty(c?.value) || _.isUndefined(c?.value))
|
||||
return redirect(RouterAuth.login);
|
||||
const token = JSON.parse(
|
||||
await unsealData(c?.value as string, {
|
||||
password: ServerEnv.value?.WIBU_PWD as string,
|
||||
})
|
||||
);
|
||||
|
||||
const token = JSON.parse(
|
||||
await unsealData(c?.value as string, {
|
||||
password: PwdCookies,
|
||||
})
|
||||
);
|
||||
|
||||
return token.id;
|
||||
return token.id;
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ export function Home_UiView({
|
||||
onClick={() => {
|
||||
if (dataUser.Profile === null) {
|
||||
return ComponentGlobal_NotifikasiPeringatan(
|
||||
"Lengkapi Data Profile"
|
||||
"Lengkapi Profile"
|
||||
);
|
||||
} else {
|
||||
if (e.link === "") {
|
||||
@@ -176,7 +176,7 @@ export function Home_UiView({
|
||||
onClick={() => {
|
||||
if (dataUser.Profile === null) {
|
||||
return ComponentGlobal_NotifikasiPeringatan(
|
||||
"Lengkapi Data Profile"
|
||||
"Lengkapi Profile"
|
||||
);
|
||||
} else {
|
||||
if (routePageJob.link === "") {
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
"use server";
|
||||
|
||||
import { myConsole } from "@/app/fun/my_console";
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import { RouterInvestasi_OLD } from "@/app/lib/router_hipmi/router_investasi";
|
||||
import { revalidatePath } from "next/cache";
|
||||
|
||||
export default async function funDeleteBeritaInvestasi(id: string) {
|
||||
const res = await prisma.beritaInvestasi.delete({
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
"use server";
|
||||
|
||||
import { myConsole } from "@/app/fun/my_console";
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import fs from "fs";
|
||||
import _ from "lodash";
|
||||
import { cookies } from "next/headers";
|
||||
import { v4 } from "uuid";
|
||||
|
||||
/**
|
||||
@@ -18,9 +16,6 @@ export async function funUploadFoto(formData: FormData, id: string) {
|
||||
const fExt = _.lowerCase(file.name.split(".").pop());
|
||||
const fRandomName = v4(fName) + "." + fExt;
|
||||
|
||||
myConsole(id);
|
||||
myConsole(fExt);
|
||||
|
||||
const upload = await prisma.images.create({
|
||||
data: {
|
||||
url: fRandomName,
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import { RouterAuth } from "@/app/lib/router_hipmi/router_auth";
|
||||
import { user_funGetOneUserId } from "@/app_modules/fun_global/get_user_token";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
export async function userSearch_getAllUser({
|
||||
page,
|
||||
@@ -10,7 +12,12 @@ export async function userSearch_getAllUser({
|
||||
page: number;
|
||||
search?: string;
|
||||
}) {
|
||||
const userLoginId = await user_funGetOneUserId();
|
||||
const authorId = await user_funGetOneUserId();
|
||||
if (!authorId) {
|
||||
redirect(RouterAuth.login);
|
||||
// return { status: 400, message: "Gagal mendapatkan authorId" };
|
||||
}
|
||||
|
||||
const takeData = 20;
|
||||
const skipData = page * takeData - takeData;
|
||||
|
||||
@@ -33,7 +40,7 @@ export async function userSearch_getAllUser({
|
||||
OR: [
|
||||
{
|
||||
NOT: {
|
||||
id: userLoginId,
|
||||
id: authorId,
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
@@ -5,9 +5,15 @@ import { MODEL_VOTING } from "../../model/interface";
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import { revalidatePath } from "next/cache";
|
||||
import _ from "lodash";
|
||||
import { RouterAuth } from "@/app/lib/router_hipmi/router_auth";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
export async function Vote_funCreate(req: MODEL_VOTING, listVote: any[]) {
|
||||
const authorId = await user_funGetOneUserId();
|
||||
if (!authorId) {
|
||||
redirect(RouterAuth.login);
|
||||
// return { status: 400, message: "Gagal mendapatkan authorId" };
|
||||
}
|
||||
|
||||
const create = await prisma.voting.create({
|
||||
data: {
|
||||
|
||||
@@ -2,17 +2,22 @@
|
||||
|
||||
import { user_funGetOneUserId } from "@/app_modules/fun_global/get_user_token";
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import { RouterAuth } from "@/app/lib/router_hipmi/router_auth";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
export async function Vote_getAllListRiwayatSaya({ page }: { page: number }) {
|
||||
const authorId = await user_funGetOneUserId();
|
||||
const takeData = 5;
|
||||
const skipData = page * takeData - takeData;
|
||||
|
||||
if (!authorId) {
|
||||
redirect(RouterAuth.login);
|
||||
// return { status: 400, message: "Gagal mendapatkan authorId" };
|
||||
}
|
||||
const takeData = 5;
|
||||
const skipData = page * takeData - takeData;
|
||||
|
||||
const data = await prisma.voting.findMany({
|
||||
take: takeData,
|
||||
skip: skipData,
|
||||
|
||||
|
||||
orderBy: {
|
||||
createdAt: "asc",
|
||||
},
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import { RouterAuth } from "@/app/lib/router_hipmi/router_auth";
|
||||
import { user_funGetOneUserId } from "@/app_modules/fun_global/get_user_token";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
export async function vote_getAllDraft({ page }: { page: number }) {
|
||||
const authorId = await user_funGetOneUserId();
|
||||
|
||||
if (!authorId) {
|
||||
redirect(RouterAuth.login);
|
||||
// return { status: 400, message: "Gagal mendapatkan authorId" };
|
||||
}
|
||||
const takeData = 10;
|
||||
const skipData = page * takeData - takeData;
|
||||
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import { RouterAuth } from "@/app/lib/router_hipmi/router_auth";
|
||||
import { user_funGetOneUserId } from "@/app_modules/fun_global/get_user_token";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
export async function vote_getAllPublish({ page }: { page: number }) {
|
||||
const authorId = await user_funGetOneUserId();
|
||||
if (!authorId) {
|
||||
redirect(RouterAuth.login);
|
||||
// return { status: 400, message: "Gagal mendapatkan authorId" };
|
||||
}
|
||||
|
||||
const takeData = 5;
|
||||
const skipData = page * takeData - takeData;
|
||||
@@ -32,6 +38,5 @@ export async function vote_getAllPublish({ page }: { page: number }) {
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import { RouterAuth } from "@/app/lib/router_hipmi/router_auth";
|
||||
import { user_funGetOneUserId } from "@/app_modules/fun_global/get_user_token";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
export async function vote_getAllReject({ page }: { page: number }) {
|
||||
const authorId = await user_funGetOneUserId();
|
||||
if (!authorId) {
|
||||
redirect(RouterAuth.login);
|
||||
// return { status: 400, message: "Gagal mendapatkan authorId" };
|
||||
}
|
||||
|
||||
const takeData = 10;
|
||||
const skipData = page * takeData - takeData;
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import { RouterAuth } from "@/app/lib/router_hipmi/router_auth";
|
||||
import { user_funGetOneUserId } from "@/app_modules/fun_global/get_user_token";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
export async function vote_getAllReview({ page }: { page: number }) {
|
||||
const authorId = await user_funGetOneUserId();
|
||||
if (!authorId) {
|
||||
redirect(RouterAuth.login);
|
||||
// return { status: 400, message: "Gagal mendapatkan authorId" };
|
||||
}
|
||||
|
||||
const takeData = 10;
|
||||
const skipData = page * takeData - takeData;
|
||||
|
||||
Reference in New Issue
Block a user