fix registrasi

deskripsi:
- fix registrasi dan middleware
This commit is contained in:
2025-02-05 17:48:45 +08:00
parent d7252b9fb3
commit 61f8e03c73
10 changed files with 199 additions and 173 deletions

View File

@@ -3,6 +3,7 @@ export {
apiGetCheckCodeOtp,
apiPostVerifikasiCodeOtp,
apiDeleteAktivasiKodeOtpByNomor,
apiFetchRegister,
};
const apiFetchLogin = async ({ nomor }: { nomor: string }) => {
@@ -43,7 +44,30 @@ const apiDeleteAktivasiKodeOtpByNomor = async ({ id }: { id: string }) => {
},
});
console.log("respone delete", await respone.json());
return await respone.json().catch(() => null);
};
const apiFetchRegister = async ({
nomor,
username,
}: {
nomor: string;
username: string;
}) => {
const data = {
username: username,
nomor: nomor,
};
const respone = await fetch("/api/auth/register", {
method: "POST",
body: JSON.stringify({ data }),
headers: {
"Content-Type": "application/json",
},
});
const result = await respone.json();
return result;
// return await respone.json().catch(() => null);
};

View File

@@ -14,8 +14,13 @@ import { useState } from "react";
import { auth_funDeleteAktivasiKodeOtpByNomor } from "../fun/fun_edit_aktivasi_kode_otp_by_id";
import Register_SkeletonView from "./skeleton";
import { clientLogger } from "@/util/clientLogger";
import { apiGetCheckCodeOtp } from "../_lib/api_fetch_auth";
import {
apiDeleteAktivasiKodeOtpByNomor,
apiFetchRegister,
apiGetCheckCodeOtp,
} from "../_lib/api_fetch_auth";
import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
import { ComponentGlobal_NotifikasiGagal } from "@/app_modules/_global/notif_global";
export default function Register() {
const router = useRouter();
@@ -48,52 +53,28 @@ export default function Register() {
}
async function onRegistarsi() {
const data = {
username: value,
nomor: nomor,
};
try {
setLoading(true);
const res = await fetch("/api/auth/register", {
method: "POST",
body: JSON.stringify({
data,
}),
headers: {
"Content-Type": "application/json",
},
});
const result = await res.json();
if (res.status === 200) {
ComponentGlobal_NotifikasiBerhasil(result.message);
localStorage.removeItem("hipmi_auth_code_id");
await auth_funDeleteAktivasiKodeOtpByNomor({
nomor: data.nomor,
});
const respone = await apiFetchRegister({ nomor: nomor, username: value });
if (respone.success) {
router.push("/waiting-room", { scroll: false });
return;
}
ComponentGlobal_NotifikasiBerhasil(respone.message);
if (res.status === 400) {
setLoading(false);
ComponentGlobal_NotifikasiPeringatan(result.message);
return;
}
try {
const responeDelete = await apiDeleteAktivasiKodeOtpByNomor({
id: idCode,
});
if (res.status === 405) {
if (responeDelete) {
localStorage.removeItem("hipmi_auth_code_id");
}
} catch (error) {
clientLogger.error("Error apiDeleteAktivasiKodeOtpByNomor:", error);
}
} else {
setLoading(false);
ComponentGlobal_NotifikasiPeringatan(result.message);
return;
}
if (res.status === 500) {
setLoading(false);
ComponentGlobal_NotifikasiPeringatan(result.message);
return;
ComponentGlobal_NotifikasiPeringatan(respone.message);
}
} catch (error) {
setLoading(false);
@@ -156,6 +137,7 @@ export default function Register() {
value.length < 5 ||
_.values(value).includes(" ")
}
style={{ transition: "0.5s" }}
loading={loading ? true : false}
loaderPosition="center"
radius={"md"}

View File

@@ -131,7 +131,6 @@ export default function Validasi() {
async function onBack() {
try {
router.back();
111;
const responeDelete = await apiDeleteAktivasiKodeOtpByNomor({
id: idCode,
});
@@ -165,13 +164,12 @@ export default function Validasi() {
setTriggerOtp(true);
setCounter(60);
setLoadingResend(false);
// router.push("/validasi", { scroll: false });
} else {
setLoadingResend(false);
ComponentGlobal_NotifikasiPeringatan(result.message);
}
} catch (error) {
console.error(error);
clientLogger.error(" Error onResend", error);
setLoadingResend(false);
ComponentGlobal_NotifikasiGagal("Terjadi Kesalahan");
}
@@ -181,26 +179,26 @@ export default function Validasi() {
<>
<UIGlobal_LayoutDefault>
<Stack h={"100vh"}>
{data && data.nomor !== "" ? (
<Box
pt={"md"}
px={"md"}
style={{
position: "sticky",
top: 0,
}}
>
<ActionIcon variant="transparent" onClick={() => onBack()}>
<Box
pt={"md"}
px={"md"}
style={{
position: "sticky",
top: 0,
}}
>
<ActionIcon variant="transparent" onClick={() => onBack()}>
{data && data.nomor !== "" ? (
<IconChevronLeft color="white" />
</ActionIcon>
</Box>
) : (
""
)}
) : (
""
)}
</ActionIcon>
</Box>
<Stack align="center" justify="center" h={"100vh"} spacing={50}>
<Title order={2} color={MainColor.yellow}>
Verifikasi Kode OTP {data.code}
Verifikasi Kode OTP
</Title>
<Stack spacing={"md"} align="center">
@@ -232,31 +230,40 @@ export default function Validasi() {
</Center>
<Stack h={"5vh"} align="center" justify="center">
<Text fs="italic" c={MainColor.white}>
Tidak menerima kode ?{" "}
{counter > 0 ? (
<Text fw={"bold"} inherit span>
{counter + "s"}
</Text>
) : loadingResend ? (
<Loader ml={"sm"} size={"xs"} color="yellow" />
<Group position="center">
<Text fs="italic" c={MainColor.white}>
Tidak menerima kode ?{" "}
</Text>
{data && data.nomor !== "" ? (
counter > 0 ? (
<Text fw={"bold"} c={MainColor.white}>
{counter + "s"}
</Text>
) : loadingResend ? (
<Loader ml={"sm"} size={"xs"} color="yellow" />
) : (
<Text
c={MainColor.white}
onClick={() => {
onResendCode();
}}
fw={"bold"}
>
Kirim ulang
</Text>
)
) : (
<Text
inherit
span
onClick={() => {
onResendCode();
}}
fw={"bold"}
>
Kirim ulang
</Text>
<CustomSkeleton height={20} radius={"xl"} width={20} />
)}
</Text>
</Group>
</Stack>
</Stack>
<Button
w={300}
disabled={inputCode.length < 4 ? true : false}
style={{
transition: "all ease 0.3s",
}}
loading={loading ? true : false}
loaderPosition="center"
radius={"md"}
@@ -265,9 +272,6 @@ export default function Validasi() {
c={"black"}
bg={MainColor.yellow}
color={"yellow"}
style={{
borderColor: AccentColor.yellow,
}}
onClick={() => {
data.nomor == "" && data.code == ""
? null
@@ -277,8 +281,6 @@ export default function Validasi() {
<Text>VERIFIKASI</Text>
</Button>
</Stack>
{/* {data.nomor == "" && data.code == "" ? <Validasi_SkeletonView /> : ""} */}
</Stack>
</UIGlobal_LayoutDefault>
</>