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
const handleVerifyOtp = async () => {
const mobile = localStorage.getItem("userMobNo");
// const mobile = "7890544527";
if (!mobile || otp.length !== 6) return;
// const handleVerifyOtp = async () => {
// const mobile = localStorage.getItem("userMobNo");
// // const mobile = "7890544527";
// 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");
// // formData.append("data", encoded_data);
// // 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",
// // headers: {
// // "Content-Type": "application/json",
// // },
// // body: formData,
// // }
// // );
// 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");
// 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(
@@ -148,60 +178,64 @@ export default function VerifyOtpPage() {
// }
// );
// const result = await res.json();
// console.log(result);
// if (!res.ok) {
// throw new Error("CBS response API failed");
// throw new Error(`CBS response API failed: ${res.status}`);
// }
// if (res.ok) {
// // navigate only after successful API hit
// 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);
// };
const handleVerifyOtp = async () => {
const mobile = localStorage.getItem("userMobNo");
if (!mobile || otp.length !== 6) return;
setIsVerifying(true);
const success = await verifyOtp(otp, mobile);
if (success) {
try {
const encoded_data = localStorage.getItem("Validate_data");
if (!encoded_data) {
console.error("Validate_data not found in localStorage");
setIsVerifying(false);
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,
}
);
// 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);
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();
window.location.href = redirectUrl; // <-- FULL PAGE REDIRECT
console.log("CBS Response:", result);
setTimeout(() => {
router.push("/eMandate/mandate_page");
}, 1000);
} catch (error) {
console.error("CBS API Error:", error);
}
}
else {
return; // ensure no more code runs
} else {
setOtp("");
}
setIsVerifying(false);
};
if (authorized === null) {
return (
<Center style={{ height: "100vh" }}>