fix: e mandate

This commit is contained in:
2025-12-15 12:18:14 +05:30
parent 793c0920f9
commit 5a6d324ec9

View File

@@ -116,92 +116,126 @@ export default function VerifyOtpPage() {
// Verify OTP using verifyOtp() Utility // 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 handleVerifyOtp = async () => {
const mobile = localStorage.getItem("userMobNo"); const mobile = localStorage.getItem("userMobNo");
// const mobile = "7890544527";
if (!mobile || otp.length !== 6) return; if (!mobile || otp.length !== 6) return;
setIsVerifying(true); setIsVerifying(true);
const success = await verifyOtp(otp, mobile); 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) { if (success) {
try { const encoded_data = localStorage.getItem("Validate_data");
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( if (!encoded_data) {
"https://apiemandate.kccb.in:9035/EMandate/auth-cbs-resp", console.error("Validate_data not found in localStorage");
{ setIsVerifying(false);
method: "POST", return;
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 { // 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(""); setOtp("");
} }
setIsVerifying(false); setIsVerifying(false);
}; };
if (authorized === null) { if (authorized === null) {
return ( return (
<Center style={{ height: "100vh" }}> <Center style={{ height: "100vh" }}>