Fix: middleware

Deskripsi
- Fix middleware
- Fix metode login ( sekarang menggunakan api )
This commit is contained in:
2024-12-02 16:24:03 +08:00
parent 45279cd37f
commit 31124c5500
55 changed files with 1675 additions and 420 deletions

View File

@@ -1,14 +1,8 @@
"use client";
import { RouterAuth } from "@/app/lib/router_hipmi/router_auth";
import { Warna } from "@/app/lib/warna";
import { AccentColor } from "@/app_modules/_global/color";
import {
ComponentGlobal_NotifikasiBerhasil,
ComponentGlobal_NotifikasiPeringatan,
} from "@/app_modules/_global/notif_global";
import { auth_Logout } from "@/app_modules/auth/fun/fun_logout";
import { gs_kodeId } from "@/app_modules/auth/state/state";
import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/_global/notif_global";
import { MODEL_USER } from "@/app_modules/home/model/interface";
import {
ActionIcon,
@@ -25,7 +19,6 @@ import {
Title,
} from "@mantine/core";
import { IconPhone, IconUser, IconUserCircle } from "@tabler/icons-react";
import { useAtom } from "jotai";
import { useRouter } from "next/navigation";
import { useState } from "react";
@@ -38,21 +31,18 @@ export function Admin_ComponentButtonUserCircle({
const [isOpenMenuUser, setOpenMenuUser] = useState(false);
const [openPop, setOpenPop] = useState(false);
const [openModal, setOpenModal] = useState(false);
const [loading, setLoading] = useState(false);
const [kodeId, setKodeId] = useAtom(gs_kodeId);
const [loadingLogout, setLoadingLogout] = useState(false);
async function onClickLogout() {
const res = await auth_Logout();
setLoadingLogout(true);
const res = await fetch(`/api/auth/logout?id=${dataUser.id}`, {
method: "GET",
});
const result = await res.json();
if (res.status === 200) {
console.log(res);
setLoadingLogout(true);
ComponentGlobal_NotifikasiBerhasil(res.message);
setKodeId("");
setOpenModal(false);
router.push(RouterAuth.login, { scroll: false });
} else {
ComponentGlobal_NotifikasiPeringatan(res.message);
ComponentGlobal_NotifikasiBerhasil(result.message);
router.push("/", { scroll: false });
}
}
@@ -114,7 +104,6 @@ export function Admin_ComponentButtonUserCircle({
<Button
onClick={() => {
setOpenModal(false);
setLoading(false);
}}
radius={50}
>

View File

@@ -4,6 +4,7 @@ import { gs_admin_ntf } from "@/app/lib/global_state";
import {
ActionIcon,
AppShell,
Button,
Divider,
Drawer,
Grid,
@@ -18,8 +19,10 @@ import {
import { useMediaQuery, useShallowEffect } from "@mantine/hooks";
import { IconBell } from "@tabler/icons-react";
import { useAtom } from "jotai";
import { useRouter } from "next/navigation";
import { useState } from "react";
import { AccentColor } from "../_global/color";
import { ComponentGlobal_NotifikasiBerhasil } from "../_global/notif_global";
import { MODEL_USER } from "../home/model/interface";
import { MODEL_NOTIFIKASI } from "../notifikasi/model/interface";
import {
@@ -47,6 +50,7 @@ export function Admin_NewLayout({
listNotifikasi: MODEL_NOTIFIKASI[];
version: string;
}) {
const router = useRouter();
const matches = useMediaQuery("(min-width: 1024px)");
const [dataUser, setDataUser] = useState(user);
const userRoleId = dataUser.masterUserRoleId;
@@ -72,6 +76,20 @@ export function Admin_NewLayout({
setDrawerNotifikasi(true);
}
const [loadingLogout, setLoadingLogout] = useState(false);
async function onClickLogout() {
setLoadingLogout(true);
const res = await fetch(`/api/auth/logout?id=${user.id}`, {
method: "GET",
});
const result = await res.json();
if (res.status === 200) {
ComponentGlobal_NotifikasiBerhasil(result.message);
router.push("/", { scroll: false });
}
}
return (
<>
<AppShell
@@ -168,6 +186,7 @@ export function Admin_NewLayout({
<Title order={4} align="center">
View Only Available For Desktop
</Title>
<Button onClick={() => onClickLogout()}>Logout</Button>
</Stack>
) : (
children