Description: Currently, the backend controllers likely perform manual checks for req.body properties (e.g., checking if email exists inside the controller), or worse, assume the data is correct. This leads to code duplication, potential server crashes due to undefined properties, and inconsistent error messages for the frontend.
To improve security and code maintainability, we should implement a robust validation layer that intercepts requests before they reach the controller logic.
Proposed Solution: Integrate a schema validation library (recommend Joi or Zod) and create a reusable middleware function. This middleware will validate the incoming request body against a defined schema and return a 400 Bad Request with clear error details if validation fails.
Description: Currently, the backend controllers likely perform manual checks for req.body properties (e.g., checking if email exists inside the controller), or worse, assume the data is correct. This leads to code duplication, potential server crashes due to undefined properties, and inconsistent error messages for the frontend.
To improve security and code maintainability, we should implement a robust validation layer that intercepts requests before they reach the controller logic.
Proposed Solution: Integrate a schema validation library (recommend Joi or Zod) and create a reusable middleware function. This middleware will validate the incoming request body against a defined schema and return a 400 Bad Request with clear error details if validation fails.