HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //proc/thread-self/root/home/arjun/projects/good-life-be/api/Auth/validator.js
import Joi from 'joi';

export const signupValidator = async (req, res, next) => {
  const schema = Joi.object({
    firstName: Joi.string().required(),
    secondName: Joi.string().allow(''),
    email: Joi.string().email().required(),
    password: Joi.string()
      .min(8)
      .regex(/[a-zA-Z0-9!@#$%^~&*(),.?":{}|<>\s]/)
      .required(),
  }).options({ stripUnknown: true });
  req.body = await schema.validateAsync(req.body, {
    abortEarly: false,
  });
  next();
};

// Login Validator
export const loginValidator = async (req, res, next) => {
  const schema = Joi.object({
    email: Joi.string().email().required(),
    password: Joi.string()
      .min(8)
      .regex(/[a-zA-Z0-9!@#$%^&*(),.?":{}|<>]/) // Simplified regex for better password validation
      .required(),
  }).options({ stripUnknown: true });

  req.body = await schema.validateAsync(req.body, {
    abortEarly: false,
  });
  next();
};

// Login Validator
export const resetPasswordValidator = async (req, res, next) => {
  const schema = Joi.object({
    token: Joi.string().required(),
    password: Joi.string()
      .min(8)
      .regex(/[a-zA-Z0-9!@#$%^&*(),.?":{}|<>]/) // Simplified regex for better password validation
      .required(),
  }).options({ stripUnknown: true });

  req.body = await schema.validateAsync(req.body, {
    abortEarly: false,
  });
  next();
};