Metronic Laravel 8.2.3 login response handle js deadcode
Hi team,
I'm working on Metronic Laravel 8.2.3 for my frontend.
Btw, when I login FE never display "Sorry, the email or password is incorrect, please try again."
It only displays:
- "You have successfully logged in!"
- "Sorry, looks like there are some errors detected, please try again."
I do search and found out in "public/assets/js/custom/authentication/sign-in/general.js"
you handle case "Sorry, the email or password is incorrect, please try again." in branch else of if (response)
if (response)
"You have successfully logged in!"
else
"Sorry, the email or password is incorrect, please try again."
I think we could never go to else branch.
Please advise.
Replies (1)
Hi,
Sorry for the delay. It seems there might be an issue with the handling of error responses in the login process. You can update the code in the catch block as follows:
.catch(function (error) {
if (error.response.status !== 200) {
Swal.fire({
text: "Sorry, the email or password is incorrect, please try again.",
icon: "error",
buttonsStyling: false,
confirmButtonText: "Ok, got it!",
customClass: {
confirmButton: "btn btn-primary"
}
});
} else {
Swal.fire({
text: "An error occurred. Please try again later.",
icon: "error",
buttonsStyling: false,
confirmButtonText: "Ok, got it!",
customClass: {
confirmButton: "btn btn-primary"
}
});
}
}); This code checks if the error response status is 422, which is the status typically used for validation errors, such as an incorrect email or password during login. If the status is not 200, it displays the appropriate error message. Otherwise, it displays a generic error message. This should ensure that users are notified when their login credentials are incorrect. We'll also make sure to address this in the next release to provide a more seamless experience. Thank you for your patience and understanding. If you have any further questions or concerns, please don't hesitate to ask.