From cfd42efe663626f74e1c72cdcb084224e36af14f Mon Sep 17 00:00:00 2001 From: abhimanyurajeesh Date: Thu, 2 Jan 2025 20:39:32 +0530 Subject: [PATCH 1/3] Invalid OPT error --- public/locale/en.json | 1 + src/components/Auth/Login.tsx | 27 ++++++++++++++++----------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/public/locale/en.json b/public/locale/en.json index f20179944d1..f03735326a6 100644 --- a/public/locale/en.json +++ b/public/locale/en.json @@ -1013,6 +1013,7 @@ "invalid_email": "Please enter a valid email address", "invalid_ip_address": "Invalid IP Address", "invalid_link_msg": "It appears that the password reset link you have used is either invalid or expired. Please request a new password reset link.", + "invalid_otp": "Invalid OTP, Please check the OPT and try Again", "invalid_password": "Password doesn't meet the requirements", "invalid_password_reset_link": "Invalid password reset link", "invalid_patient_data": "Invalid Patient Data", diff --git a/src/components/Auth/Login.tsx b/src/components/Auth/Login.tsx index aa65e533a2f..cc4a3602434 100644 --- a/src/components/Auth/Login.tsx +++ b/src/components/Auth/Login.tsx @@ -167,19 +167,24 @@ const Login = (props: { forgot?: boolean }) => { }, 200); } }, + + //Invalid OTP error handling onError: (error: HTTPError) => { - const errorData = error.cause as { errors: Array<{ otp: string }> }; - const errors = errorData?.errors; - if (Array.isArray(errors) && errors.length > 0) { - // BE returns a different format for invalid OTP - // TODO: fix this - //const firstError = errors[0] as OtpError; - //setOtpError(firstError.msg); - const firstError = errors[0]; - setOtpValidationError(firstError.otp); - } else { - setOtpValidationError(t("invalid_otp")); + let errorMessage = t("invalid_otp"); + Notification.Error({ msg: t("invalid_otp") }); + if ( + error.cause && + Array.isArray(error.cause.errors) && + error.cause.errors.length > 0 + ) { + const otpError = error.cause.errors.find((e) => e.otp); + if (otpError && otpError.otp) { + errorMessage = otpError.otp; + } + } else if (error.message) { + errorMessage = error.message; } + setOtpValidationError(errorMessage); }, }); From 6215ebe8007fa4863a5c610d28e31694400b7cdb Mon Sep 17 00:00:00 2001 From: abhimanyurajeesh Date: Thu, 2 Jan 2025 20:41:27 +0530 Subject: [PATCH 2/3] Invalid OPT error --- src/components/Auth/Login.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Auth/Login.tsx b/src/components/Auth/Login.tsx index cc4a3602434..99bc17a44c8 100644 --- a/src/components/Auth/Login.tsx +++ b/src/components/Auth/Login.tsx @@ -170,8 +170,8 @@ const Login = (props: { forgot?: boolean }) => { //Invalid OTP error handling onError: (error: HTTPError) => { - let errorMessage = t("invalid_otp"); Notification.Error({ msg: t("invalid_otp") }); + let errorMessage = t("invalid_otp"); if ( error.cause && Array.isArray(error.cause.errors) && From 86c681e1a6e96c599f50cf1f4f216e8c041b431e Mon Sep 17 00:00:00 2001 From: abhimanyurajeesh Date: Thu, 2 Jan 2025 23:32:37 +0530 Subject: [PATCH 3/3] Invalid OTP errorMessage --- src/components/Auth/Login.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Auth/Login.tsx b/src/components/Auth/Login.tsx index 99bc17a44c8..392fe43db70 100644 --- a/src/components/Auth/Login.tsx +++ b/src/components/Auth/Login.tsx @@ -170,7 +170,6 @@ const Login = (props: { forgot?: boolean }) => { //Invalid OTP error handling onError: (error: HTTPError) => { - Notification.Error({ msg: t("invalid_otp") }); let errorMessage = t("invalid_otp"); if ( error.cause && @@ -185,6 +184,7 @@ const Login = (props: { forgot?: boolean }) => { errorMessage = error.message; } setOtpValidationError(errorMessage); + Notification.Error({ msg: errorMessage }); }, });