amupedia2021 / amupedia-web

Source code of the website.
https://www.amupedia.site/
MIT License
163 stars 177 forks source link

Improve Error Handling and Refactor Code for User Registration and Login ⚡ #557

Closed Nishitbaria closed 1 year ago

Nishitbaria commented 1 year ago

Description:

Current Behavior:

The current code for user registration and login in the project lacks proper error handling and could be refactored to improve readability and maintainability.

  1. In the user registration endpoint, there is no validation for the incoming request data. As a result, the code is prone to errors and might accept invalid or incomplete data.

  2. The error handling in both the registration and login endpoints is not consistent and could be improved to provide more informative error messages to clients.

  3. The password hashing logic is repeated in both endpoints, leading to code duplication. A refactoring approach can be used to centralize this logic and make the code more maintainable.

  4. The response status codes are not always appropriate. For example, when login credentials are incorrect, the response status should be 401 Unauthorized, but the current code uses 400 Bad Request.

Desired Behavior:

We should enhance the code by implementing the following improvements:

  1. Integrate express-validator to validate incoming request data for user registration and login endpoints.

  2. Refactor the code to use a helper function for password hashing, reducing code duplication.

  3. Implement consistent and informative error handling to provide better feedback to clients when errors occur.

  4. Use proper HTTP status codes for responses to indicate success or failure more accurately.

Proposed Changes:

  1. Implement express-validator for data validation in both the registration and login endpoints.

  2. Create a helper function to handle password hashing, eliminating code repetition in the endpoints.

  3. Refactor the error handling to provide more informative error messages and appropriate HTTP status codes.

  4. Separate the registration and login logic into different functions, making the code more modular and organized.

The proposed changes will enhance the security, maintainability, and user experience of the application.

github-actions[bot] commented 1 year ago

Hello @Nishitbaria! Thank you for raising this issue.

Please make sure to follow our Contributing Guidelines. 💪🏻 Don't forget to ⭐ our Project-Amupedia. 📔

Our review team will carefully assess the issue and reach out to you soon! 😇 We appreciate your patience! 😀

github-actions[bot] commented 1 year ago

This issue is stale because it has been open for 14 days with no activity.