fix: e mandate

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

View File

@@ -116,28 +116,58 @@ export default function VerifyOtpPage() {
// Verify OTP using verifyOtp() Utility // Verify OTP using verifyOtp() Utility
const handleVerifyOtp = async () => { // const handleVerifyOtp = async () => {
const mobile = localStorage.getItem("userMobNo"); // const mobile = localStorage.getItem("userMobNo");
// const mobile = "7890544527"; // // 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) { // // 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"); // // const encoded_data = localStorage.getItem("Validate_data");
// // formData.append("data", encoded_data);
// // const res = await fetch( // // const res = await fetch(
// // `https://apiemandate.kccb.in:9035/EMandate/auth-cbs-resp?data=${encoded_data}`, // // "https://apiemandate.kccb.in:9035/EMandate/auth-cbs-resp",
// // { // // {
// // method: "POST", // // method: "POST",
// // headers: { // // body: formData,
// // "Content-Type": "application/json",
// // },
// // } // // }
// // ); // // );
// const formData = new 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"); // 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); // formData.append("data", encoded_data);
// const res = await fetch( // const res = await fetch(
@@ -148,60 +178,64 @@ export default function VerifyOtpPage() {
// } // }
// ); // );
// const result = await res.json();
// console.log(result);
// if (!res.ok) { // if (!res.ok) {
// throw new Error("CBS response API failed"); // throw new Error(`CBS response API failed: ${res.status}`);
// } // }
// if (res.ok) { // const contentType = res.headers.get("content-type");
// // navigate only after successful API hit // const result =
// contentType && contentType.includes("application/json")
// ? await res.json()
// : await res.text();
// console.log("CBS Response:", result);
// setTimeout(() => { // setTimeout(() => {
// router.push("/eMandate/mandate_page"); // router.push("/eMandate/mandate_page");
// }, 1500); // }, 1000);
// } catch (error) {
// console.error("CBS API Error:", error);
// } // }
// } // }
// else {
// setOtp("");
// }
// setIsVerifying(false);
// };
const handleVerifyOtp = async () => {
const mobile = localStorage.getItem("userMobNo");
if (!mobile || otp.length !== 6) return;
setIsVerifying(true);
const success = await verifyOtp(otp, mobile);
if (success) { if (success) {
try {
const encoded_data = localStorage.getItem("Validate_data"); const encoded_data = localStorage.getItem("Validate_data");
if (!encoded_data) { if (!encoded_data) {
console.error("Validate_data not found in localStorage"); console.error("Validate_data not found in localStorage");
setIsVerifying(false);
return; return;
} }
const formData = new FormData();
formData.append("data", encoded_data);
const res = await fetch( // Redirect to API URL with encoded data as query param
"https://apiemandate.kccb.in:9035/EMandate/auth-cbs-resp", const redirectUrl =
{ "https://apiemandate.kccb.in:9035/EMandate/auth-cbs-resp?data=" +
method: "POST", encodeURIComponent(encoded_data);
body: formData,
}
);
if (!res.ok) { window.location.href = redirectUrl; // <-- FULL PAGE REDIRECT
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); return; // ensure no more code runs
setTimeout(() => { } else {
router.push("/eMandate/mandate_page");
}, 1000);
} catch (error) {
console.error("CBS API Error:", error);
}
}
else {
setOtp(""); setOtp("");
} }
setIsVerifying(false); setIsVerifying(false);
}; };
if (authorized === null) { if (authorized === null) {
return ( return (
<Center style={{ height: "100vh" }}> <Center style={{ height: "100vh" }}>