fix logout

This commit is contained in:
2025-06-11 14:16:34 +08:00
parent 9dbcf94a34
commit 893c6cbe27
5 changed files with 61 additions and 40 deletions

View File

@@ -4,6 +4,7 @@ export {
apiPostVerifikasiCodeOtp,
apiDeleteAktivasiKodeOtpByNomor,
apiFetchRegister,
apiFetchLogout,
};
const apiFetchLogin = async ({ nomor }: { nomor: string }) => {
@@ -71,3 +72,14 @@ const apiFetchRegister = async ({
return result;
// return await respone.json().catch(() => null);
};
const apiFetchLogout = async ({ id }: { id: string }) => {
const respone = await fetch(`/api/auth/logout?id=${id}`, {
method: "GET",
});
const result = await respone.json();
return result;
};

View File

@@ -20,12 +20,12 @@ export default function InvalidUser() {
await fetch("/api/auth/logout", {
method: "GET",
});
router.push("/login", {scroll: false});
router.push("/", { scroll: false });
setIsLoading(false);
} catch (error) {
setIsLoading(false);
console.error("Gagal menghapus cookie:", error);
}
}
};
return (
@@ -33,7 +33,8 @@ export default function InvalidUser() {
<UIGlobal_LayoutDefault>
<Stack align="center" justify="center" spacing="md" h={"100vh"}>
<Title order={3} c={MainColor.white} align="center">
Maaf, Anda tidak memiliki izin untuk mengakses halaman ini. Silakan logout terlebih dahulu.
Maaf, Anda tidak memiliki izin untuk mengakses halaman ini. Silakan
logout terlebih dahulu.
</Title>
<Button
loading={isLoading}

View File

@@ -1,32 +1,33 @@
"use client";
import { Warna } from "@/lib/warna";
import { MainColor } from "@/app_modules/_global/color";
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 { Warna } from "@/lib/warna";
import { ActionIcon, Button, Stack, Text } from "@mantine/core";
import { IconLogout } from "@tabler/icons-react";
import { useRouter } from "next/navigation";
import { useState } from "react";
import { auth_Logout } from "../fun/fun_logout";
import { RouterAuth } from "@/lib/router_hipmi/router_auth";
import { MainColor } from "@/app_modules/_global/color";
import { apiFetchLogout } from "../_lib/api_fetch_auth";
export default function Component_ButtonLogout({userId}: {userId: string}) {
export default function Component_ButtonLogout({ userId }: { userId: string }) {
const router = useRouter();
const [opened, setOpened] = useState(false);
const [loading, setLoading] = useState(false);
async function onClickLogout() {
setLoading(true);
const res = await fetch(`/api/auth/logout?id=${userId}`, {
method: "GET",
});
try {
setLoading(true);
const response = await apiFetchLogout({ id: userId });
const result = await res.json();
if (res.status === 200) {
ComponentGlobal_NotifikasiBerhasil(result.message);
router.push("/", { scroll: false });
if (response && response.success) {
ComponentGlobal_NotifikasiBerhasil(response.message);
router.replace("/", { scroll: false });
}
} catch (error) {
console.error(error);
} finally {
setLoading(false);
}
}