diff --git a/controllers/authControllers.ts b/controllers/authControllers.ts index e9b0eb9..dfc6f74 100644 --- a/controllers/authControllers.ts +++ b/controllers/authControllers.ts @@ -8,13 +8,27 @@ import { Types } from "mongoose"; const signup = async (req: Request, res: Response, next: NextFunction) => { try { let user; - const { email } = req.body; + const { email,dob } = req.body; user = await UserModel.UserSchema.findOne({ email: email }); if (user) { return res.status(httpStatus.BAD_REQUEST).send({ message: "Email already in use", }); } + if(!isNaN(Date.parse(dob))){ + const dobDate = new Date(dob); + const currentDate = new Date(); + if(dobDate >= currentDate){ + return res.status(httpStatus.BAD_REQUEST).send({ + message: "Invalid date of birth", + }); + } + } + else{ + return res.status(httpStatus.BAD_REQUEST).send({ + message: "Invalid date of birth", + }); + } user = await UserModel.UserSchema.create(req.body); const accessToken = jwt.sign(user.toJSON(), process.env.JWT_SECRET); return res.status(httpStatus.CREATED).json({