-
Notifications
You must be signed in to change notification settings - Fork 53
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
[BUG] Joi Validation not used correctly #40
Comments
@lambeboluwatife , in recent we have used asyncHandler. Once see the code again and then raise a pr if issue is still persists. |
Okay, I'll check but I don't think it's related |
@divyansh-2005 In regards to the asyncHandler changes, there are some errors from the PR. Like this: It's either you undo the merge, or I should fix it here and make a PR with my own new changes |
@divyansh-2005 I've been able to fix the issues. But I don't see the need for the asyncHandler, which makes the code bulkier and more complicated—waiting for your reply before I make a PR. |
if errors are fixed then make a pr |
Okay then. |
I've just made a PR |
Describe the bug
The data from the req.body for the register user controller and login controller are not validated using Joi correctly. The username, email, and password are not correctly extracted from
userRegisterSchema.validate
.After validation, these values should be extracted from
userRegisterSchema.validate
instead of using variables directly from req.body, sinceuserRegisterSchema.validate
contains the sanitized values.The errors are not properly handled. Error handling is mixed between synchronous and asynchronous code. try-catch more consistently. There should be an error check if the error is from Joi or the req.body not only the generic 500 status code error.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Destructuring
userRegisterSchema.validate
: After validating the inputs, I destructured the username, email, and password fromuserRegisterSchema.validate
rather than directly from req.body.Proper Error Handling: The try-catch block catches all errors, and I ensure that Joi validation errors are specifically handled using error.isJoi. For other types of errors (such as database-related errors), it logs them and returns a generic server error.
Screenshots before
screenshots after fix*
check list
Additional context
@divyansh-2005 I want to fix this issue, please let it be assigned to me.
The text was updated successfully, but these errors were encountered: