Skip to content

Commit

Permalink
Fixed: No notification shown when invalid OTP is entered (#9667)
Browse files Browse the repository at this point in the history
  • Loading branch information
abhimanyurajeesh authored Jan 3, 2025
1 parent 67aa098 commit ee27ecd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
1 change: 1 addition & 0 deletions public/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
27 changes: 16 additions & 11 deletions src/components/Auth/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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");
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);
Notification.Error({ msg: errorMessage });
},
});

Expand Down

0 comments on commit ee27ecd

Please sign in to comment.