Fix: Cookies
This commit is contained in:
13
src/app/(user)/login/page.tsx
Normal file
13
src/app/(user)/login/page.tsx
Normal file
@@ -0,0 +1,13 @@
|
||||
import { funCheckCookies } from "@/app_modules/_global/fun/get/fun_check_cookies";
|
||||
import { Login } from "@/app_modules/auth";
|
||||
import versionUpdate from "../../../../package.json";
|
||||
|
||||
export default async function Page() {
|
||||
const version = versionUpdate.version;
|
||||
|
||||
return (
|
||||
<>
|
||||
<Login version={version} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
8
src/app/(user)/register/[id]/page.tsx
Normal file
8
src/app/(user)/register/[id]/page.tsx
Normal file
@@ -0,0 +1,8 @@
|
||||
import { Register } from "@/app_modules/auth";
|
||||
import { auth_getCodeOtpByNumber } from "@/app_modules/auth/fun/get_kode_otp_by_id";
|
||||
|
||||
export default async function Page({ params }: { params: { id: string } }) {
|
||||
let otpId = params.id;
|
||||
const dataOtp = await auth_getCodeOtpByNumber({ kodeId: otpId });
|
||||
return <Register dataOtp={dataOtp} />;
|
||||
}
|
||||
9
src/app/(user)/validasi/[id]/page.tsx
Normal file
9
src/app/(user)/validasi/[id]/page.tsx
Normal file
@@ -0,0 +1,9 @@
|
||||
import { Validasi } from "@/app_modules/auth";
|
||||
import { auth_getCodeOtpByNumber } from "@/app_modules/auth/fun/get_kode_otp_by_id";
|
||||
|
||||
export default async function Page({ params }: { params: { id: string } }) {
|
||||
let kodeId = params.id;
|
||||
const dataOtp = await auth_getCodeOtpByNumber({ kodeId: kodeId });
|
||||
|
||||
return <Validasi dataOtp={dataOtp as any} />;
|
||||
}
|
||||
@@ -1,9 +1,15 @@
|
||||
import { Login } from "@/app_modules/auth";
|
||||
import versionUpdate from "../../../../../package.json";
|
||||
import { funCheckCookies } from "@/app_modules/_global/fun/get/fun_check_cookies";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
export default async function Page() {
|
||||
const version = versionUpdate.version;
|
||||
|
||||
const checkCookies = await funCheckCookies();
|
||||
console.log(checkCookies, "ini halaman login");
|
||||
if (!checkCookies) return redirect("/");
|
||||
|
||||
return (
|
||||
<>
|
||||
<Login version={version} />
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
|
||||
import { SplashScreen } from "@/app_modules/auth";
|
||||
|
||||
export default async function PageSplash() {
|
||||
const userLoginId = await funGetUserIdByToken();
|
||||
|
||||
return (
|
||||
<>
|
||||
<SplashScreen userLoginId={userLoginId} />
|
||||
<SplashScreen checkCookies/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
import { Validasi } from "@/app_modules/auth";
|
||||
import { auth_getCodeOtpByNumber } from "@/app_modules/auth/fun/get_kode_otp_by_id";
|
||||
import { redirect } from "next/navigation";
|
||||
import { RouterAuth } from "@/app/lib/router_hipmi/router_auth";
|
||||
|
||||
export default async function Page({ params }: { params: { id: string } }) {
|
||||
let kodeId = params.id;
|
||||
const dataOtp = await auth_getCodeOtpByNumber({ kodeId: kodeId });
|
||||
// if (dataOtp === null) return redirect(RouterAuth.login);
|
||||
|
||||
|
||||
return <Validasi dataOtp={dataOtp as any} />;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,21 @@
|
||||
import { RouterAdminDashboard } from "@/app/lib/router_hipmi/router_admin";
|
||||
import { RouterHome } from "@/app/lib/router_hipmi/router_home";
|
||||
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
|
||||
import { funGlobal_getUserById } from "@/app_modules/_global/fun/get/fun_get_user_by_id";
|
||||
import { CheckCookies_UiView } from "@/app_modules/check_cookies";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
export default function Page() {
|
||||
return <CheckCookies_UiView />;
|
||||
export default async function Page() {
|
||||
const userLoginId = await funGetUserIdByToken();
|
||||
const dataUser = await funGlobal_getUserById({ userId: userLoginId });
|
||||
|
||||
if (dataUser?.masterUserRoleId === "1") {
|
||||
return redirect(RouterHome.main_home);
|
||||
}
|
||||
|
||||
if (dataUser?.masterUserRoleId !== "1") {
|
||||
return redirect(RouterAdminDashboard.splash_admin);
|
||||
}
|
||||
|
||||
// return <CheckCookies_UiView />;
|
||||
}
|
||||
|
||||
@@ -1,27 +1,24 @@
|
||||
import { RouterAdminDashboard } from "@/app/lib/router_hipmi/router_admin";
|
||||
import { RouterHome } from "@/app/lib/router_hipmi/router_home";
|
||||
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
|
||||
import { HomeView } from "@/app_modules/home";
|
||||
import { user_getOneByUserId } from "@/app_modules/home/fun/get/get_one_user_by_id";
|
||||
import { job_getTwoForHomeView } from "@/app_modules/job/fun/get/get_two_for_home_view";
|
||||
import notifikasi_countUserNotifikasi from "@/app_modules/notifikasi/fun/count/fun_count_by_id";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
export default async function Page() {
|
||||
const userLoginId = await funGetUserIdByToken();
|
||||
|
||||
const dataUser = await user_getOneByUserId(userLoginId as string);
|
||||
const dataJob = await job_getTwoForHomeView();
|
||||
|
||||
if (dataUser?.active === false) {
|
||||
return redirect(RouterHome.home_user_non_active);
|
||||
}
|
||||
|
||||
if (dataUser?.masterUserRoleId === "2" || dataUser?.masterUserRoleId === "3")
|
||||
return redirect(RouterAdminDashboard.splash_admin);
|
||||
|
||||
const countNotifikasi = await notifikasi_countUserNotifikasi();
|
||||
|
||||
// console.log(userLoginId, "ini di home");
|
||||
// console.log(dataUser, "ini di home");
|
||||
|
||||
// if (dataUser?.active === false) {
|
||||
// return redirect(RouterHome.home_user_non_active);
|
||||
// }
|
||||
// if (dataUser?.masterUserRoleId === "2" || dataUser?.masterUserRoleId === "3")
|
||||
// return redirect(RouterAdminDashboard.splash_admin);
|
||||
|
||||
return (
|
||||
<>
|
||||
<HomeView
|
||||
|
||||
@@ -1,11 +1,38 @@
|
||||
"use client";
|
||||
import { CheckCookies_UiLayout } from "@/app_modules/check_cookies";
|
||||
import { RealtimeProvider } from "../lib";
|
||||
import { funCheckCookies } from "@/app_modules/_global/fun/get/fun_check_cookies";
|
||||
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
|
||||
import { ServerEnv } from "../lib/server_env";
|
||||
import { funGlobal_getUserById } from "@/app_modules/_global/fun/get/fun_get_user_by_id";
|
||||
import { RouterHome } from "../lib/router_hipmi/router_home";
|
||||
import { RouterAdminDashboard } from "../lib/router_hipmi/router_admin";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
export default async function Layout({
|
||||
children,
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
}) {
|
||||
const checkCookies = await funCheckCookies();
|
||||
if (!checkCookies) return redirect("/");
|
||||
|
||||
const userLoginId = await funGetUserIdByToken();
|
||||
const WIBU_REALTIME_TOKEN = process.env.NEXT_PUBLIC_WIBU_REALTIME_TOKEN;
|
||||
// console.log(WIBU_REALTIME_TOKEN, "check cookies di layout dalam");
|
||||
|
||||
export default function Layout({ children }: { children: React.ReactNode }) {
|
||||
return (
|
||||
<>
|
||||
<RealtimeProvider
|
||||
userLoginId={userLoginId as string}
|
||||
WIBU_REALTIME_TOKEN={
|
||||
ServerEnv.value?.NEXT_PUBLIC_WIBU_REALTIME_TOKEN as string
|
||||
}
|
||||
/>
|
||||
|
||||
{children}
|
||||
{/* <CheckCookies_UiLayout>{children}</CheckCookies_UiLayout> */}
|
||||
{/* <CheckCookies_UiLayout dataUser={dataUser as any}>
|
||||
{children}
|
||||
</CheckCookies_UiLayout> */}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,16 +2,16 @@ import { RouterHome } from "@/app/lib/router_hipmi/router_home";
|
||||
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
|
||||
import { Home_UserNonActive } from "@/app_modules/home";
|
||||
import { user_getOneByUserId } from "@/app_modules/home/fun/get/get_one_user_by_id";
|
||||
import { redirect } from "next/navigation";
|
||||
// import { redirect } from "next/navigation";
|
||||
|
||||
export default async function Page() {
|
||||
const userLoginId = await funGetUserIdByToken();
|
||||
|
||||
const dataUser = await user_getOneByUserId(userLoginId as string);
|
||||
|
||||
if (dataUser?.active === true) {
|
||||
return redirect(RouterHome.main_home);
|
||||
}
|
||||
// if (dataUser?.active === true) {
|
||||
// return redirect(RouterHome.main_home);
|
||||
// }
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
|
||||
import { CheckCookies_UiView } from "@/app_modules/check_cookies";
|
||||
import { LayoutVote_DetailSemuaRiwayat } from "@/app_modules/vote";
|
||||
import React from "react";
|
||||
|
||||
@@ -12,9 +11,7 @@ export default async function Layout({
|
||||
}) {
|
||||
const votingId = params.id;
|
||||
const userLoginId = await funGetUserIdByToken();
|
||||
|
||||
if (!userLoginId) return <CheckCookies_UiView />;
|
||||
|
||||
|
||||
return (
|
||||
<>
|
||||
<LayoutVote_DetailSemuaRiwayat
|
||||
|
||||
@@ -6,6 +6,8 @@ import dotenv from "dotenv";
|
||||
import { ServerEnv } from "./lib/server_env";
|
||||
import { RealtimeProvider } from "./lib";
|
||||
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
|
||||
import { funCheckCookies } from "@/app_modules/_global/fun/get/fun_check_cookies";
|
||||
import { redirect } from "next/navigation";
|
||||
dotenv.config({
|
||||
path: ".env",
|
||||
});
|
||||
@@ -18,6 +20,8 @@ const Client_KEY = process.env.Client_KEY!;
|
||||
const Server_KEY = process.env.Server_KEY!;
|
||||
const MAPBOX_TOKEN = process.env.MAPBOX_TOKEN!;
|
||||
const WS_APIKEY = process.env.WS_APIKEY!;
|
||||
const NEXT_PUBLIC_WIBU_REALTIME_TOKEN =
|
||||
process.env.NEXT_PUBLIC_WIBU_REALTIME_TOKEN!;
|
||||
|
||||
if (!DATABASE_URL) throw new Error("Require DATABASE_URL");
|
||||
if (!WIBU_PWD) throw new Error("Require WIBU_PWD");
|
||||
@@ -25,6 +29,8 @@ if (!Client_KEY) throw new Error("Require Client_KEY");
|
||||
if (!Server_KEY) throw new Error("Require Server_KEY");
|
||||
if (!MAPBOX_TOKEN) throw new Error("Require MAPBOX_TOKEN");
|
||||
if (!WS_APIKEY) throw new Error("Require WS_APIKEY");
|
||||
if (!NEXT_PUBLIC_WIBU_REALTIME_TOKEN)
|
||||
throw new Error("Require NEXT_PUBLIC_WIBU_REALTIME_TOKEN");
|
||||
|
||||
const envObject = {
|
||||
DATABASE_URL,
|
||||
@@ -33,6 +39,7 @@ const envObject = {
|
||||
Server_KEY,
|
||||
MAPBOX_TOKEN,
|
||||
WS_APIKEY,
|
||||
NEXT_PUBLIC_WIBU_REALTIME_TOKEN,
|
||||
};
|
||||
ServerEnv.set(envObject);
|
||||
|
||||
@@ -41,15 +48,22 @@ export default async function RootLayout({
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
}) {
|
||||
// if (!token) return <>Require Token Storage</>;
|
||||
const userLoginId = await funGetUserIdByToken();
|
||||
if (!token) return <>Require Token Storage</>;
|
||||
// const userLoginId = await funGetUserIdByToken();
|
||||
// const WIBU_REALTIME_TOKEN = process.env.NEXT_PUBLIC_WIBU_REALTIME_TOKEN;
|
||||
// console.log(WIBU_REALTIME_TOKEN, "WIBU_REALTIME_TOKEN");
|
||||
|
||||
|
||||
|
||||
return (
|
||||
<RootStyleRegistry>
|
||||
{/* <MqttLoader />
|
||||
<TokenProvider token={token} envObject={envObject} /> */}
|
||||
<RealtimeProvider userLoginId={userLoginId as string} />
|
||||
{/* <MqttLoader /> */}
|
||||
<TokenProvider token={token} envObject={envObject} />
|
||||
{/* <RealtimeProvider
|
||||
userLoginId={userLoginId as string}
|
||||
WIBU_REALTIME_TOKEN={
|
||||
ServerEnv.value?.NEXT_PUBLIC_WIBU_REALTIME_TOKEN as string
|
||||
}
|
||||
/> */}
|
||||
{children}
|
||||
</RootStyleRegistry>
|
||||
);
|
||||
|
||||
@@ -16,6 +16,10 @@ import {
|
||||
IRealtimeData,
|
||||
} from "./global_state";
|
||||
|
||||
// const WIBU_REALTIME_TOKEN: string | undefined =
|
||||
// process.env.NEXT_PUBLIC_WIBU_REALTIME_TOKEN;
|
||||
|
||||
// Pasang tipe data di package WibuRealtime sebagai type adata setData
|
||||
export type TypeNotification = {
|
||||
type: "message" | "notification" | "trigger";
|
||||
pushNotificationTo: "ADMIN" | "USER";
|
||||
@@ -23,12 +27,12 @@ export type TypeNotification = {
|
||||
userLoginId?: string;
|
||||
};
|
||||
|
||||
const WIBU_REALTIME_TOKEN: string | undefined =
|
||||
process.env.NEXT_PUBLIC_WIBU_REALTIME_TOKEN;
|
||||
export default function RealtimeProvider({
|
||||
userLoginId,
|
||||
WIBU_REALTIME_TOKEN,
|
||||
}: {
|
||||
userLoginId: string;
|
||||
WIBU_REALTIME_TOKEN: string;
|
||||
}) {
|
||||
const [dataRealtime, setDataRealtime] = useAtom(gs_realtimeData);
|
||||
const [newAdminNtf, setNewAdminNtf] = useAtom(gs_admin_ntf);
|
||||
@@ -58,9 +62,11 @@ export default function RealtimeProvider({
|
||||
);
|
||||
|
||||
useShallowEffect(() => {
|
||||
if (WIBU_REALTIME_TOKEN === undefined) return alert("gak dapet key");
|
||||
// if (WIBU_REALTIME_TOKEN === undefined) return alert("gak dapet key");
|
||||
try {
|
||||
WibuRealtime.init({
|
||||
project: "hipmi",
|
||||
WIBU_REALTIME_TOKEN: WIBU_REALTIME_TOKEN,
|
||||
onData(data: TypeNotification) {
|
||||
if (
|
||||
data.type == "notification" &&
|
||||
@@ -154,12 +160,9 @@ export default function RealtimeProvider({
|
||||
}
|
||||
// ---------------------- VOTING ------------------------- //
|
||||
},
|
||||
|
||||
project: "hipmi",
|
||||
WIBU_REALTIME_TOKEN: WIBU_REALTIME_TOKEN,
|
||||
});
|
||||
} catch (error) {
|
||||
alert("error realtime");
|
||||
console.log(error);
|
||||
}
|
||||
}, []);
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ type ENV = {
|
||||
Server_KEY: string;
|
||||
MAPBOX_TOKEN: string;
|
||||
WS_APIKEY: string;
|
||||
NEXT_PUBLIC_WIBU_REALTIME_TOKEN: string;
|
||||
};
|
||||
export class ServerEnv {
|
||||
static value: ENV | null = null;
|
||||
|
||||
@@ -1,5 +1,24 @@
|
||||
import { funCheckCookies } from "@/app_modules/_global/fun/get/fun_check_cookies";
|
||||
import PageSplash from "./dev/auth/splash/page";
|
||||
import { redirect } from "next/navigation";
|
||||
import { Login, SplashScreen } from "@/app_modules/auth";
|
||||
import { RouterAuth } from "./lib/router_hipmi/router_auth";
|
||||
import versionUpdate from "../../package.json";
|
||||
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
|
||||
import { funGlobal_getUserById } from "@/app_modules/_global/fun/get/fun_get_user_by_id";
|
||||
import { RouterHome } from "./lib/router_hipmi/router_home";
|
||||
import { RouterAdminDashboard } from "./lib/router_hipmi/router_admin";
|
||||
|
||||
export default async function Page() {
|
||||
return <PageSplash/>
|
||||
const version = versionUpdate.version;
|
||||
|
||||
const checkCookies = await funCheckCookies();
|
||||
// console.log(checkCookies, "ini check cookies di page awal");
|
||||
if (checkCookies) return redirect("/dev/check-cookies");
|
||||
return redirect("/login");
|
||||
// const WIBU_REALTIME_TOKEN = process.env.NEXT_PUBLIC_WIBU_REALTIME_TOKEN;
|
||||
|
||||
// return <Login version={version} />;
|
||||
// return <SplashScreen checkCookies={checkCookies} />;
|
||||
return <PageSplash />;
|
||||
}
|
||||
|
||||
28
src/app_modules/_global/fun/get/fun_check_cookies.ts
Normal file
28
src/app_modules/_global/fun/get/fun_check_cookies.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
"use server";
|
||||
|
||||
import { ServerEnv } from "@/app/lib/server_env";
|
||||
import { unsealData } from "iron-session";
|
||||
import _ from "lodash";
|
||||
import { cookies } from "next/headers";
|
||||
|
||||
export async function funCheckCookies() {
|
||||
const c = cookies().get("mySession");
|
||||
|
||||
if (!c || !c?.value || _.isEmpty(c?.value) || _.isUndefined(c?.value)) {
|
||||
// console.log("return pertama");
|
||||
return false;
|
||||
}
|
||||
|
||||
const token = JSON.parse(
|
||||
await unsealData(c?.value as string, {
|
||||
password: ServerEnv.value?.WIBU_PWD as string,
|
||||
})
|
||||
);
|
||||
|
||||
if (_.isEmpty(token)) {
|
||||
// console.log("return kedua");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1,17 +1,26 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import { ServerEnv } from "@/app/lib/server_env";
|
||||
import { unsealData } from "iron-session";
|
||||
import { cookies } from "next/headers";
|
||||
|
||||
export async function funGetUserIdByToken() {
|
||||
const c = cookies().get("mySession");
|
||||
const token = c?.value
|
||||
const cekToken = await prisma.userSession.findFirst({
|
||||
where: {
|
||||
token: token,
|
||||
},
|
||||
});
|
||||
const c = cookies().get("mySession");
|
||||
|
||||
if (cekToken === null) return null
|
||||
return cekToken.userId;
|
||||
const token = JSON.parse(
|
||||
await unsealData(c?.value as string, {
|
||||
password: process.env.WIBU_PWD as string,
|
||||
})
|
||||
);
|
||||
|
||||
return token.id;
|
||||
// const token = c?.value
|
||||
// const cekToken = await prisma.userSession.findFirst({
|
||||
// where: {
|
||||
// token: token,
|
||||
// },
|
||||
// });
|
||||
|
||||
// if (cekToken === null) return null
|
||||
// return cekToken.userId;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { ServerEnv } from "@/app/lib/server_env";
|
||||
import { TokenStorage } from "@/app/lib/token";
|
||||
import { envs } from "@/lib/envs";
|
||||
|
||||
export async function funGlobal_UploadToStorage({
|
||||
file,
|
||||
@@ -7,7 +9,7 @@ export async function funGlobal_UploadToStorage({
|
||||
file: File;
|
||||
dirId: string;
|
||||
}) {
|
||||
if (!file) console.log("Tidak ada file");
|
||||
const Env_WS_APIKEY = TokenStorage.value;
|
||||
|
||||
const allowedMimeTypes = [
|
||||
"image/png",
|
||||
@@ -35,7 +37,7 @@ export async function funGlobal_UploadToStorage({
|
||||
method: "POST",
|
||||
body: formData,
|
||||
headers: {
|
||||
Authorization: `Bearer ${TokenStorage.value}`,
|
||||
Authorization: `Bearer ${Env_WS_APIKEY}`,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -52,4 +54,6 @@ export async function funGlobal_UploadToStorage({
|
||||
console.error("Error:", error);
|
||||
return { success: false, data: {} };
|
||||
}
|
||||
|
||||
return { success: false, data: { id: "" } };
|
||||
}
|
||||
|
||||
@@ -1,17 +1,14 @@
|
||||
"use client";
|
||||
|
||||
import {
|
||||
Divider,
|
||||
Grid,
|
||||
Group,
|
||||
Paper,
|
||||
Stack,
|
||||
Text,
|
||||
Title
|
||||
} from "@mantine/core";
|
||||
import { Divider, Grid, Group, Paper, Stack, Text, Title } from "@mantine/core";
|
||||
|
||||
|
||||
export default function AdminMain({countUser, countPorto}: {countUser: number, countPorto: number} ) {
|
||||
export default function AdminMain({
|
||||
countUser,
|
||||
countPorto,
|
||||
}: {
|
||||
countUser: number;
|
||||
countPorto: number;
|
||||
}) {
|
||||
const listBox = [
|
||||
{
|
||||
id: 1,
|
||||
@@ -34,21 +31,11 @@ export default function AdminMain({countUser, countPorto}: {countUser: number, c
|
||||
<Stack spacing={"sm"}>
|
||||
<Title>Main Dashboard</Title>
|
||||
<Divider mb={"md"} />
|
||||
{/* <Stack align="center" justify="center" h={"80vh"}>
|
||||
<Title>Cooming Soon !!</Title>
|
||||
</Stack> */}
|
||||
|
||||
<Grid>
|
||||
{listBox.map((e) => (
|
||||
<Grid.Col md={4} lg={4} key={e.id}>
|
||||
<Paper
|
||||
withBorder
|
||||
// bg={`${e.color}.2`}
|
||||
shadow="md"
|
||||
radius="md"
|
||||
p="md"
|
||||
// sx={{ borderColor: e.color, borderStyle: "solid" }}
|
||||
>
|
||||
<Paper withBorder shadow="md" radius="md" p="md">
|
||||
<Group position="center">
|
||||
<Stack align="center" spacing={0}>
|
||||
<Text>{e.name}</Text>
|
||||
@@ -67,41 +54,3 @@ export default function AdminMain({countUser, countPorto}: {countUser: number, c
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
// const PieChart = () => {
|
||||
// const option: echarts.EChartsOption = {
|
||||
// title: {},
|
||||
// tooltip: {
|
||||
// trigger: "item",
|
||||
// },
|
||||
// legend: {
|
||||
// top: "bottom",
|
||||
// },
|
||||
// series: [
|
||||
// {
|
||||
// name: "Anggota Partai",
|
||||
// type: "pie",
|
||||
// bottom: "40",
|
||||
// data: [
|
||||
// { value: 10, name: "Laki-Laki" },
|
||||
// { value: 20, name: "Perempuan" },
|
||||
// ],
|
||||
// },
|
||||
// ],
|
||||
// };
|
||||
|
||||
// return (
|
||||
// <>
|
||||
// <Box
|
||||
// sx={{
|
||||
// backgroundColor: "gray",
|
||||
// }}
|
||||
// >
|
||||
// <Text ta={"center"} fz={20} fw={700}>
|
||||
// Jenis Kelamin
|
||||
// </Text>
|
||||
// <EChartsReact style={{ height: 300 }} option={option} />
|
||||
// </Box>
|
||||
// </>
|
||||
// );
|
||||
// };
|
||||
|
||||
@@ -32,7 +32,8 @@ export default function Login({ version }: { version: string }) {
|
||||
if (res.status === 200) {
|
||||
setLoading(true);
|
||||
ComponentGlobal_NotifikasiBerhasil(res.message, 2000);
|
||||
router.push(RouterAuth.validasi + res.kodeId, { scroll: false });
|
||||
// router.push(RouterAuth.validasi + res.kodeId, { scroll: false });
|
||||
router.push("/validasi/" + res.kodeId, { scroll: false });
|
||||
} else {
|
||||
ComponentGlobal_NotifikasiPeringatan(res.message);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ export default function Component_Logout() {
|
||||
const res = await auth_Logout();
|
||||
if (res.status === 200) {
|
||||
ComponentGlobal_NotifikasiBerhasil(res.message);
|
||||
router.push(RouterAuth.login, { scroll: false });
|
||||
router.push("/login", { scroll: false });
|
||||
} else {
|
||||
ComponentGlobal_NotifikasiPeringatan(res.message);
|
||||
}
|
||||
|
||||
@@ -1,26 +1,56 @@
|
||||
"use client";
|
||||
|
||||
import { RouterAdminDashboard } from "@/app/lib/router_hipmi/router_admin";
|
||||
import { RouterAuth } from "@/app/lib/router_hipmi/router_auth";
|
||||
import { RouterHome } from "@/app/lib/router_hipmi/router_home";
|
||||
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
|
||||
import { funGlobal_getUserById } from "@/app_modules/_global/fun/get/fun_get_user_by_id";
|
||||
import { MODEL_USER } from "@/app_modules/home/model/interface";
|
||||
import { Avatar, BackgroundImage, Center, Image, Stack } from "@mantine/core";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
import { useRouter } from "next/navigation";
|
||||
|
||||
export default function SplashScreen({ userLoginId }: { userLoginId: any }) {
|
||||
export default function SplashScreen({
|
||||
checkCookies,
|
||||
}: {
|
||||
checkCookies: boolean;
|
||||
}) {
|
||||
const router = useRouter();
|
||||
|
||||
useShallowEffect(() => {
|
||||
if (!userLoginId) {
|
||||
setTimeout(() => {
|
||||
return router.push(RouterAuth.login, { scroll: false });
|
||||
}, 1000);
|
||||
} else {
|
||||
setTimeout(() => {
|
||||
return router.push(RouterHome.main_home, { scroll: false });
|
||||
}, 1000);
|
||||
}
|
||||
// if (!checkCookies) return router.push(RouterAuth.login, { scroll: false });
|
||||
// onCheckUser();
|
||||
|
||||
// setTimeout(() => {
|
||||
// router.push(RouterAuth.login, { scroll: false });
|
||||
// }, 1000);
|
||||
// if (!userLoginId) {
|
||||
// setTimeout(() => {
|
||||
// router.push(RouterAuth.login, { scroll: false });
|
||||
// }, 1000);
|
||||
// } else {
|
||||
// dataUser.masterUserRoleId === "1"
|
||||
// ? setTimeout(() => {
|
||||
// return router.push(RouterHome.main_home, { scroll: false });
|
||||
// }, 1000)
|
||||
// : setTimeout(() => {
|
||||
// return router.push(RouterAdminDashboard.splash_admin, {
|
||||
// scroll: false,
|
||||
// });
|
||||
// }, 1000);
|
||||
// }
|
||||
}, []);
|
||||
|
||||
// async function onCheckUser() {
|
||||
// const userLoginId = await funGetUserIdByToken();
|
||||
// const dataUser = await funGlobal_getUserById({ userId: userLoginId });
|
||||
|
||||
// if (dataUser?.masterUserRoleId == "1")
|
||||
// return router.push(RouterHome.main_home);
|
||||
|
||||
// return router.push(RouterAdminDashboard.splash_admin);
|
||||
// }
|
||||
|
||||
return (
|
||||
<>
|
||||
<BackgroundImage
|
||||
|
||||
@@ -3,27 +3,40 @@
|
||||
import { RouterAuth } from "@/app/lib/router_hipmi/router_auth";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { MODEL_USER } from "../home/model/interface";
|
||||
import { RouterHome } from "@/app/lib/router_hipmi/router_home";
|
||||
import { RouterAdminDashboard } from "@/app/lib/router_hipmi/router_admin";
|
||||
|
||||
export function CheckCookies_UiLayout({
|
||||
children,
|
||||
dataUser,
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
dataUser: MODEL_USER;
|
||||
}) {
|
||||
const router = useRouter();
|
||||
|
||||
useShallowEffect(() => {
|
||||
onCheckCookies();
|
||||
}, []);
|
||||
// useShallowEffect(() => {
|
||||
// onCheckCookies();
|
||||
// }, []);
|
||||
|
||||
async function onCheckCookies() {
|
||||
const cek = await fetch("/api/check-cookies");
|
||||
// async function onCheckCookies() {
|
||||
// const cek = await fetch("/api/check-cookies");
|
||||
|
||||
const result = await cek.json();
|
||||
// const result = await cek.json();
|
||||
|
||||
if (result.success === false) {
|
||||
router.push(RouterAuth.login, { scroll: false });
|
||||
}
|
||||
}
|
||||
// if (result.success === false) {
|
||||
// router.push(RouterAuth.login, { scroll: false });
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (dataUser.masterUserRoleId === "1") {
|
||||
// router.push(RouterHome.main_home, { scroll: false });
|
||||
// }
|
||||
|
||||
// if (dataUser.masterUserRoleId !== "1") {
|
||||
// router.push(RouterAdminDashboard.splash_admin, { scroll: false });
|
||||
// }
|
||||
|
||||
return children;
|
||||
}
|
||||
|
||||
@@ -31,6 +31,8 @@ import { useState } from "react";
|
||||
import { Donasi_funCreate } from "../fun/create/fun_create_donasi";
|
||||
import { gs_donasi_hot_menu, gs_donasi_tabs_posting } from "../global_state";
|
||||
import { MODEL_DONASI_TEMPORARY } from "../model/interface";
|
||||
import { IRealtimeData } from "@/app/lib/global_state";
|
||||
import { WibuRealtime } from "wibu-pkg";
|
||||
|
||||
export default function CreateCeritaPenggalangDonasi({
|
||||
dataTemporary,
|
||||
@@ -90,7 +92,16 @@ export default function CreateCeritaPenggalangDonasi({
|
||||
});
|
||||
|
||||
if (res.status === 201) {
|
||||
const dataNotif: any = {
|
||||
// const dataNotif: any = {
|
||||
// appId: res.data?.id as any,
|
||||
// status: res.data?.DonasiMaster_Status?.name as any,
|
||||
// userId: res.data?.authorId as any,
|
||||
// pesan: res.data?.title as any,
|
||||
// kategoriApp: "DONASI",
|
||||
// title: "Donasi baru",
|
||||
// };
|
||||
|
||||
const dataNotifikasi: IRealtimeData = {
|
||||
appId: res.data?.id as any,
|
||||
status: res.data?.DonasiMaster_Status?.name as any,
|
||||
userId: res.data?.authorId as any,
|
||||
@@ -100,16 +111,25 @@ export default function CreateCeritaPenggalangDonasi({
|
||||
};
|
||||
|
||||
const notif = await notifikasiToAdmin_funCreate({
|
||||
data: dataNotif as any,
|
||||
data: dataNotifikasi as any,
|
||||
});
|
||||
|
||||
if (notif.status === 201) {
|
||||
mqtt_client.publish(
|
||||
"ADMIN",
|
||||
JSON.stringify({
|
||||
count: 1,
|
||||
})
|
||||
);
|
||||
// mqtt_client.publish(
|
||||
// "ADMIN",
|
||||
// JSON.stringify({
|
||||
// count: 1,
|
||||
// })
|
||||
// );
|
||||
|
||||
WibuRealtime.setData({
|
||||
type: "notification",
|
||||
pushNotificationTo: "ADMIN",
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
setDonasiHotMenu(1);
|
||||
ComponentGlobal_NotifikasiBerhasil(res.message);
|
||||
router.push(RouterDonasi.status_galang_dana({ id: "2" }), {
|
||||
|
||||
@@ -5,14 +5,14 @@ import { ServerEnv } from "@/app/lib/server_env";
|
||||
import { unsealData } from "iron-session";
|
||||
import _ from "lodash";
|
||||
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("mySession");
|
||||
if (!c || !c?.value || _.isEmpty(c?.value) || _.isUndefined(c?.value))
|
||||
return redirect(RouterAuth.login);
|
||||
// if (!c || !c?.value || _.isEmpty(c?.value) || _.isUndefined(c?.value))
|
||||
// return re-di-re-ct(RouterAuth.login);
|
||||
|
||||
const token = JSON.parse(
|
||||
await unsealData(c?.value as string, {
|
||||
|
||||
@@ -49,6 +49,8 @@ export default function HomeView({
|
||||
onLoad(loadNotif);
|
||||
}
|
||||
|
||||
// console.log(dataUser, "dipage")
|
||||
|
||||
return (
|
||||
<>
|
||||
<UIGlobal_LayoutTamplate
|
||||
|
||||
@@ -19,6 +19,7 @@ import { WibuRealtime } from "wibu-pkg";
|
||||
import { job_funCreateNoFile, job_funCreateWithFile } from "../../fun";
|
||||
import { gs_job_hot_menu } from "../../global_state";
|
||||
import { MODEL_JOB } from "../../model/interface";
|
||||
import { envs } from "@/lib/envs";
|
||||
|
||||
function Job_ComponentButtonSaveCreate({
|
||||
value,
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
import _ from "lodash";
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
|
||||
// This function can be marked `async` if using `await` inside
|
||||
export function middleware(request: NextRequest) {
|
||||
let cookies = request.cookies.get("mySession");
|
||||
console.log(cookies);
|
||||
|
||||
if (
|
||||
!cookies ||
|
||||
!cookies?.value ||
|
||||
_.isEmpty(cookies?.value) ||
|
||||
_.isUndefined(cookies?.value)
|
||||
) {
|
||||
return NextResponse.redirect(new URL("/dev/auth/login", request.url));
|
||||
}
|
||||
}
|
||||
|
||||
export const config = {
|
||||
matcher: ["/((?!_next|static|favicon.ico|manifest).*)"],
|
||||
};
|
||||
28
src/middleware.txt
Normal file
28
src/middleware.txt
Normal file
@@ -0,0 +1,28 @@
|
||||
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
|
||||
import { user_getOneByUserId } from "@/app_modules/home/fun/get/get_one_user_by_id";
|
||||
import { unsealData } from "iron-session";
|
||||
import _ from "lodash";
|
||||
import { NextResponse } from "next/server";
|
||||
import type { NextRequest } from "next/server";
|
||||
import { RouterHome } from "./app/lib/router_hipmi/router_home";
|
||||
|
||||
|
||||
// This function can be marked `async` if using `await` inside
|
||||
export function middleware(request: NextRequest) {
|
||||
let c = request.cookies.get("mySession");
|
||||
|
||||
if (!c || !c?.value || _.isEmpty(c?.value) || _.isUndefined(c?.value)) {
|
||||
console.log("tidak ada user middleware");
|
||||
|
||||
|
||||
// return NextResponse.redirect(new URL("/dev/auth/login", request.url));
|
||||
// return NextResponse.redirect(new URL(RouterAuth.login, request.url));
|
||||
} else {
|
||||
console.log("ada user middleware");
|
||||
return NextResponse.redirect(new URL(RouterHome.main_home, request.url));
|
||||
}
|
||||
}
|
||||
|
||||
export const config = {
|
||||
matcher: ["/((?!_next|static|favicon.ico|manifest).*)"],
|
||||
};
|
||||
Reference in New Issue
Block a user