From 5a6d324ec989af8357259d0b7ac86f0ea3019994 Mon Sep 17 00:00:00 2001 From: "tomosa.sarkar" Date: Mon, 15 Dec 2025 12:18:14 +0530 Subject: [PATCH] fix: e mandate --- src/app/eMandate/otp_page/page.tsx | 174 +++++++++++++++++------------ 1 file changed, 104 insertions(+), 70 deletions(-) diff --git a/src/app/eMandate/otp_page/page.tsx b/src/app/eMandate/otp_page/page.tsx index 786637a..ac8e513 100644 --- a/src/app/eMandate/otp_page/page.tsx +++ b/src/app/eMandate/otp_page/page.tsx @@ -116,92 +116,126 @@ export default function VerifyOtpPage() { // Verify OTP using verifyOtp() Utility + // const handleVerifyOtp = async () => { + // const mobile = localStorage.getItem("userMobNo"); + // // const mobile = "7890544527"; + // if (!mobile || otp.length !== 6) return; + + // setIsVerifying(true); + + // const success = await verifyOtp(otp, mobile); + + // // if (success) { + // // // const encoded_data = localStorage.getItem("Validate_data"); + // // // const res = await fetch( + // // // `https://apiemandate.kccb.in:9035/EMandate/auth-cbs-resp?data=${encoded_data}`, + // // // { + // // // method: "POST", + // // // headers: { + // // // "Content-Type": "application/json", + // // // }, + // // // } + // // // ); + // // const formData = new FormData(); + // // const encoded_data = localStorage.getItem("Validate_data"); + // // formData.append("data", encoded_data); + + // // const res = await fetch( + // // "https://apiemandate.kccb.in:9035/EMandate/auth-cbs-resp", + // // { + // // method: "POST", + // // body: formData, + // // } + // // ); + + // // const result = await res.json(); + // // console.log(result); + // // if (!res.ok) { + // // throw new Error("CBS response API failed"); + // // } + // // if (res.ok) { + // // // navigate only after successful API hit + // // setTimeout(() => { + // // router.push("/eMandate/mandate_page"); + // // }, 1500); + // // } + // // } + // if (success) { + // try { + // const encoded_data = localStorage.getItem("Validate_data"); + // if (!encoded_data) { + // console.error("Validate_data not found in localStorage"); + // return; + // } + // const formData = new FormData(); + // formData.append("data", encoded_data); + + // const res = await fetch( + // "https://apiemandate.kccb.in:9035/EMandate/auth-cbs-resp", + // { + // method: "POST", + // body: formData, + // } + // ); + + // if (!res.ok) { + // throw new Error(`CBS response API failed: ${res.status}`); + // } + // const contentType = res.headers.get("content-type"); + // const result = + // contentType && contentType.includes("application/json") + // ? await res.json() + // : await res.text(); + + // console.log("CBS Response:", result); + // setTimeout(() => { + // router.push("/eMandate/mandate_page"); + // }, 1000); + + // } catch (error) { + // console.error("CBS API Error:", error); + // } + // } + // else { + // setOtp(""); + // } + // setIsVerifying(false); + // }; const handleVerifyOtp = async () => { const mobile = localStorage.getItem("userMobNo"); - // const mobile = "7890544527"; + if (!mobile || otp.length !== 6) return; setIsVerifying(true); const success = await verifyOtp(otp, mobile); - // if (success) { - // // const encoded_data = localStorage.getItem("Validate_data"); - // // const res = await fetch( - // // `https://apiemandate.kccb.in:9035/EMandate/auth-cbs-resp?data=${encoded_data}`, - // // { - // // method: "POST", - // // headers: { - // // "Content-Type": "application/json", - // // }, - // // } - // // ); - // const formData = new FormData(); - // const encoded_data = localStorage.getItem("Validate_data"); - // formData.append("data", encoded_data); - - // const res = await fetch( - // "https://apiemandate.kccb.in:9035/EMandate/auth-cbs-resp", - // { - // method: "POST", - // body: formData, - // } - // ); - - // const result = await res.json(); - // console.log(result); - // if (!res.ok) { - // throw new Error("CBS response API failed"); - // } - // if (res.ok) { - // // navigate only after successful API hit - // setTimeout(() => { - // router.push("/eMandate/mandate_page"); - // }, 1500); - // } - // } if (success) { - try { - const encoded_data = localStorage.getItem("Validate_data"); - if (!encoded_data) { - console.error("Validate_data not found in localStorage"); - return; - } - const formData = new FormData(); - formData.append("data", encoded_data); + const encoded_data = localStorage.getItem("Validate_data"); - const res = await fetch( - "https://apiemandate.kccb.in:9035/EMandate/auth-cbs-resp", - { - method: "POST", - body: formData, - } - ); - - if (!res.ok) { - throw new Error(`CBS response API failed: ${res.status}`); - } - const contentType = res.headers.get("content-type"); - const result = - contentType && contentType.includes("application/json") - ? await res.json() - : await res.text(); - - console.log("CBS Response:", result); - setTimeout(() => { - router.push("/eMandate/mandate_page"); - }, 1000); - - } catch (error) { - console.error("CBS API Error:", error); + if (!encoded_data) { + console.error("Validate_data not found in localStorage"); + setIsVerifying(false); + return; } - } - else { + + // Redirect to API URL with encoded data as query param + const redirectUrl = + "https://apiemandate.kccb.in:9035/EMandate/auth-cbs-resp?data=" + + encodeURIComponent(encoded_data); + + window.location.href = redirectUrl; // <-- FULL PAGE REDIRECT + + return; // ensure no more code runs + } else { setOtp(""); } + setIsVerifying(false); }; + + if (authorized === null) { return (