From 9be5884cafa059ee984bcc8327a831c0b2bd3bf5 Mon Sep 17 00:00:00 2001 From: Rama Priyanto Date: Wed, 18 Jun 2025 14:36:01 +0700 Subject: [PATCH] fix:error handler --- components/form/login.tsx | 172 +++++++++++++++--------------- components/landing/HeaderNews.tsx | 2 +- components/landing/NewsTicker.tsx | 2 +- 3 files changed, 88 insertions(+), 88 deletions(-) diff --git a/components/form/login.tsx b/components/form/login.tsx index d4d792f..d117ff5 100644 --- a/components/form/login.tsx +++ b/components/form/login.tsx @@ -69,98 +69,98 @@ export default function Login() { error("Username & Password Wajib Diisi !"); } else { // login dengan otp - loading(); - const response: any = await emailValidation(data); - if (response?.error) { - console.log("error", response); - if (response?.message?.messages[0]?.includes("failed to send mail")) { - error("Gagal Mengirim OTP"); - return false; - } + // loading(); + // const response: any = await emailValidation(data); + // if (response?.error) { + // console.log("error", response); + // if (response?.message?.messages[0]?.includes("failed to send mail")) { + // error("Gagal Mengirim OTP"); + // return false; + // } - if (response?.message?.messages[0]?.includes("username")) { - error("Username / Password Tidak Sesuai"); - return false; - } - error("Unknown Error"); - return false; - } - close(); - if (response?.data?.messages[0] === "Continue to setup email") { - setFirstLogin(true); - } else { - setNeedOtp(true); - } + // if (response?.message?.messages[0]?.includes("username")) { + // error("Username / Password Tidak Sesuai"); + // return false; + // } + // error("Unknown Error"); + // return false; + // } + // close(); + // if (response?.data?.messages[0] === "Continue to setup email") { + // setFirstLogin(true); + // } else { + // setNeedOtp(true); + // } // login tanpa otp - // loading(); - // const response = await postSignIn(data); - // if (response?.error) { - // error("Username / Password Tidak Sesuai"); - // } else { - // const profile = await getProfile(response?.data?.data?.access_token); - // const dateTime: any = new Date(); + loading(); + const response = await postSignIn(data); + if (response?.error) { + error("Username / Password Tidak Sesuai"); + } else { + const profile = await getProfile(response?.data?.data?.access_token); + const dateTime: any = new Date(); - // const newTime: any = dateTime.getTime() + 10 * 60 * 1000; + const newTime: any = dateTime.getTime() + 10 * 60 * 1000; - // Cookies.set("access_token", response?.data?.data?.access_token, { - // expires: 1, - // }); - // Cookies.set("refresh_token", response?.data?.data?.refresh_token, { - // expires: 1, - // }); - // Cookies.set("time_refresh", newTime, { - // expires: 1, - // }); - // Cookies.set("is_first_login", "true", { - // secure: true, - // sameSite: "strict", - // }); - // const resActivity = await saveActivity( - // { - // activityTypeId: 1, - // url: "https://kontenhumas.com/auth", - // userId: profile?.data?.data?.id, - // }, - // accessData?.id_token - // ); - // Cookies.set("profile_picture", profile?.data?.data?.profilePictureUrl, { - // expires: 1, - // }); - // Cookies.set("uie", profile?.data?.data?.id, { - // expires: 1, - // }); - // Cookies.set("ufne", profile?.data?.data?.fullname, { - // expires: 1, - // }); - // Cookies.set("ulie", profile?.data?.data?.userLevelGroup, { - // expires: 1, - // }); - // Cookies.set("username", profile?.data?.data?.username, { - // expires: 1, - // }); - // Cookies.set("urie", profile?.data?.data?.userRoleId, { - // expires: 1, - // }); - // Cookies.set("masterPoldaId", profile?.data?.data?.masterPoldaId, { - // expires: 1, - // }); - // Cookies.set("ulne", profile?.data?.data?.userLevelId, { - // expires: 1, - // }); - // // Cookies.set("urce", profile?.data?.data?.roleCode, { - // // expires: 1, - // // }); - // Cookies.set("email", profile?.data?.data?.email, { - // expires: 1, - // }); - // router.push("/admin/dashboard"); - // Cookies.set("status", "login", { - // expires: 1, - // }); + Cookies.set("access_token", response?.data?.data?.access_token, { + expires: 1, + }); + Cookies.set("refresh_token", response?.data?.data?.refresh_token, { + expires: 1, + }); + Cookies.set("time_refresh", newTime, { + expires: 1, + }); + Cookies.set("is_first_login", "true", { + secure: true, + sameSite: "strict", + }); + const resActivity = await saveActivity( + { + activityTypeId: 1, + url: "https://kontenhumas.com/auth", + userId: profile?.data?.data?.id, + }, + accessData?.id_token + ); + Cookies.set("profile_picture", profile?.data?.data?.profilePictureUrl, { + expires: 1, + }); + Cookies.set("uie", profile?.data?.data?.id, { + expires: 1, + }); + Cookies.set("ufne", profile?.data?.data?.fullname, { + expires: 1, + }); + Cookies.set("ulie", profile?.data?.data?.userLevelGroup, { + expires: 1, + }); + Cookies.set("username", profile?.data?.data?.username, { + expires: 1, + }); + Cookies.set("urie", profile?.data?.data?.userRoleId, { + expires: 1, + }); + Cookies.set("masterPoldaId", profile?.data?.data?.masterPoldaId, { + expires: 1, + }); + Cookies.set("ulne", profile?.data?.data?.userLevelId, { + expires: 1, + }); + // Cookies.set("urce", profile?.data?.data?.roleCode, { + // expires: 1, + // }); + Cookies.set("email", profile?.data?.data?.email, { + expires: 1, + }); + router.push("/admin/dashboard"); + Cookies.set("status", "login", { + expires: 1, + }); - // close(); - // } + close(); + } } }; diff --git a/components/landing/HeaderNews.tsx b/components/landing/HeaderNews.tsx index 0dcc908..e21dd65 100644 --- a/components/landing/HeaderNews.tsx +++ b/components/landing/HeaderNews.tsx @@ -357,7 +357,7 @@ export default function HeaderNews() { - {article.length > 0 ? ( + {article?.length > 0 ? ( article.map((list: any, index: number) => (
BREAKING NEWS
- {article.length > 0 ? ( + {article?.length > 0 ? (