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

[BUG] Joi Validation not used correctly #40

Open
3 tasks done
lambeboluwatife opened this issue Oct 4, 2024 · 7 comments · May be fixed by #73
Open
3 tasks done

[BUG] Joi Validation not used correctly #40

lambeboluwatife opened this issue Oct 4, 2024 · 7 comments · May be fixed by #73
Assignees
Labels
bug Something isn't working gssoc-ext hacktoberfest

Comments

@lambeboluwatife
Copy link

lambeboluwatife commented Oct 4, 2024

Describe the bug

  1. 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, since userRegisterSchema.validate contains the sanitized values.

  2. 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:

  1. Go to 'the backend folder'
  2. Then go to 'the controllers' folder'
  3. Click on 'authController.js'
  4. See error

Expected behavior

  1. Destructuring userRegisterSchema.validate: After validating the inputs, I destructured the username, email, and password from userRegisterSchema.validate rather than directly from req.body.

  2. 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
Screenshot (32)
Screenshot (33)
Screenshot (37)

screenshots after fix*
Screenshot (34)
Screenshot (35)

check list

  • I am contributing under GSSoC-ext
  • I am contributing under hacktoberfest
  • I follow contribution guidlines

Additional context
@divyansh-2005 I want to fix this issue, please let it be assigned to me.

@divyansh-2005
Copy link
Owner

@lambeboluwatife , in recent we have used asyncHandler. Once see the code again and then raise a pr if issue is still persists.

@lambeboluwatife
Copy link
Author

Okay, I'll check but I don't think it's related

@lambeboluwatife
Copy link
Author

@divyansh-2005 In regards to the asyncHandler changes, there are some errors from the PR. Like this:
image

It's either you undo the merge, or I should fix it here and make a PR with my own new changes

@lambeboluwatife
Copy link
Author

@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.

@divyansh-2005
Copy link
Owner

if errors are fixed then make a pr

@lambeboluwatife
Copy link
Author

Okay then.
I'll do that now

lambeboluwatife added a commit to lambeboluwatife/my-calendar-app that referenced this issue Oct 6, 2024
@lambeboluwatife lambeboluwatife linked a pull request Oct 6, 2024 that will close this issue
11 tasks
@lambeboluwatife
Copy link
Author

I've just made a PR
@divyansh-2005

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working gssoc-ext hacktoberfest
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants