Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed: No notification shown when invalid OTP is entered #9667

Merged
merged 4 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading