auth.validation.ts46 lines, 1.3 KB
| 1 | import { body, query } from "express-validator"; |
| 2 | |
| 3 | export const registerValidation = [ |
| 4 | body("email") |
| 5 | .isEmail() |
| 6 | .withMessage("Please provide a valid email address") |
| 7 | .normalizeEmail(), |
| 8 | body("password") |
| 9 | .isLength({ min: 8 }) |
| 10 | .withMessage("Password must be at least 8 characters long") |
| 11 | .matches(/\d/) |
| 12 | .withMessage("Password must contain at least one number") |
| 13 | .matches(/[a-z]/) |
| 14 | .withMessage("Password must contain at least one lowercase letter") |
| 15 | .matches(/[A-Z]/) |
| 16 | .withMessage("Password must contain at least one uppercase letter"), |
| 17 | body("name") |
| 18 | .notEmpty() |
| 19 | .withMessage("Name is required") |
| 20 | .trim() |
| 21 | .isLength({ min: 2 }) |
| 22 | .withMessage("Name must be at least 2 characters long"), |
| 23 | ]; |
| 24 | |
| 25 | export const loginValidation = [ |
| 26 | body("email") |
| 27 | .isEmail() |
| 28 | .withMessage("Please provide a valid email address") |
| 29 | .normalizeEmail(), |
| 30 | body("password").notEmpty().withMessage("Password is required"), |
| 31 | ]; |
| 32 | |
| 33 | export const verifyEmailValidation = [ |
| 34 | query("token") |
| 35 | .notEmpty() |
| 36 | .withMessage("Verification token is required") |
| 37 | .isString() |
| 38 | .withMessage("Verification token must be a string"), |
| 39 | ]; |
| 40 | |
| 41 | export const resendVerificationValidation = [ |
| 42 | body("email") |
| 43 | .isEmail() |
| 44 | .withMessage("Please provide a valid email address") |
| 45 | .normalizeEmail(), |
| 46 | ]; |