Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion controllers/authControllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(), <string>process.env.JWT_SECRET);
return res.status(httpStatus.CREATED).json({
Expand Down