Files
starr-philproperties/validators/auth.validator.js
T
2026-05-05 23:18:47 +08:00

46 lines
2.1 KiB
JavaScript

/***********************************************************************************************************************************************************************
* File Name: auth.validator.js
* Type of Program: Validator
* Description: express-validator rule chains for authentication endpoints.
* - registerValidator → POST /auth/register
* - loginValidator → POST /auth/login
* - verifyOTPValidator → POST /auth/verify-otp
* - resendOTPValidator → POST /auth/resend-otp
* - changePassValidator → POST /auth/change-password
* Author: rgrgogu
* Date Created: Oct. 6, 2025
***********************************************************************************************************************************************************************/
const { body } = require('express-validator');
const registerValidator = [
body('email').isEmail().withMessage('Valid email is required.'),
body('password')
.isLength({ min: 8 })
.withMessage('Password must be at least 8 characters.')
.matches(/[A-Z]/).withMessage('Password must contain an uppercase letter.')
.matches(/[0-9]/).withMessage('Password must contain a number.'),
];
const loginValidator = [
body('email').isEmail().withMessage('Valid email is required.'),
body('password').notEmpty().withMessage('Password is required.'),
];
const verifyOTPValidator = [
body('email').isEmail(),
body('otp').isLength({ min: 6, max: 6 }).isNumeric().withMessage('OTP must be 6 digits.'),
];
const resendOTPValidator = [
body('email').isEmail().withMessage('Valid email is required.'),
];
const changePassValidator = [
body('current_password').notEmpty().withMessage('Current password is required.'),
body('new_password')
.isLength({ min: 8 }).withMessage('New password must be at least 8 characters.')
.matches(/[A-Z]/).withMessage('Must contain an uppercase letter.')
.matches(/[0-9]/).withMessage('Must contain a number.'),
];
module.exports = { registerValidator, loginValidator, verifyOTPValidator, resendOTPValidator, changePassValidator };