You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
652 B

module.exports = function (req, res, next) {
const { email, name, password } = req.body;
function validEmail(userEmail) {
return /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(userEmail);
}
if (req.path === "/register") {
if (![email, name, password].every(Boolean)) {
return res.json("Missing Credentials");
} else if (!validEmail(email)) {
return res.json("Invalid Email");
}
} else if (req.path === "/login") {
if (![email, password].every(Boolean)) {
return res.json("Missing Credentials");
} else if (!validEmail(email)) {
return res.json("Invalid Email");
}
}
next();
};