From fbca0c9e942c5b9334f55e77c57594f9f685b50e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Gierwia=C5=82o?= Date: Sat, 6 Dec 2025 18:59:56 +0100 Subject: [PATCH] fix(validators): correct WSDC ID optional field validation Fixed validation issue where empty/null wsdcId was incorrectly validated. Changed from `.optional()` to `.optional({ nullable: true, checkFalsy: true })` to properly skip validation for falsy values (null, undefined, empty string). This allows users to register without WSDC ID without triggering "WSDC ID must be numeric" validation error. --- backend/src/middleware/validators.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/backend/src/middleware/validators.js b/backend/src/middleware/validators.js index 884fdfd..bc951aa 100644 --- a/backend/src/middleware/validators.js +++ b/backend/src/middleware/validators.js @@ -70,9 +70,10 @@ const registerValidation = [ .matches(/^[a-zA-ZÀ-ÿ\s'-]+$/) .withMessage('Last name contains invalid characters'), body('wsdcId') - .optional() - .trim() - .matches(/^\d{1,10}$/) + .optional({ nullable: true, checkFalsy: true }) + .isLength({ min: 1, max: 10 }) + .withMessage('WSDC ID must be between 1 and 10 characters') + .matches(/^\d+$/) .withMessage('WSDC ID must be numeric (max 10 digits)'), // Turnstile CAPTCHA (only required if TURNSTILE_SECRET_KEY is set) ...(process.env.TURNSTILE_SECRET_KEY