diff --git a/src/app/eMandate/login/page/page.tsx b/src/app/eMandate/login/page/page.tsx index 6066c2b..6002c99 100644 --- a/src/app/eMandate/login/page/page.tsx +++ b/src/app/eMandate/login/page/page.tsx @@ -169,7 +169,7 @@ function LoginEmandate() { }), }); const result = await response.json(); - localStorage.setItem("Validate_data", result); + localStorage.setItem("Validate_data", result.data); console.log("Validate Result : ", result); if (response.ok) { router.push("/eMandate/otp_page"); diff --git a/src/app/eMandate/otp_page/page.tsx b/src/app/eMandate/otp_page/page.tsx index b4cb0a5..786637a 100644 --- a/src/app/eMandate/otp_page/page.tsx +++ b/src/app/eMandate/otp_page/page.tsx @@ -125,33 +125,80 @@ export default function VerifyOtpPage() { 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) { - 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", - }, + try { + const encoded_data = localStorage.getItem("Validate_data"); + if (!encoded_data) { + console.error("Validate_data not found in localStorage"); + return; } - ); - 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 + 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"); - }, 1500); + }, 1000); + + } catch (error) { + console.error("CBS API Error:", error); } } else { setOtp(""); } - setIsVerifying(false); };