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 />;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user