fix: send eMandate encrypted data into form data

This commit is contained in:
2025-12-10 10:56:36 +05:30
parent c8377b7a88
commit 793c0920f9
2 changed files with 66 additions and 19 deletions

View File

@@ -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");

View File

@@ -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) {
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?data=${encoded_data}`,
"https://apiemandate.kccb.in:9035/EMandate/auth-cbs-resp",
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: formData,
}
);
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);
};