-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuserValidator.js
More file actions
29 lines (24 loc) · 890 Bytes
/
userValidator.js
File metadata and controls
29 lines (24 loc) · 890 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const { body } = require("express-validator");
const User = require("../../models/User");
const loginValidator = [
body("email", "Invalid does not Empty").not().isEmpty(),
body("email", "Invalid email").isEmail(),
body("password", "The minimum password length is 8 characters").isLength({
min: 8,
}),
];
const registerValidator = [
body("name", "username does not Empty").not().isEmpty(),
body("email", "Invalid email").isEmail(),
// validate unique email
body("email").custom(async (value) => {
return User.findOne({ email: value }).then((user) => {
if (user) return Promise.reject("User with this email already exists!");
});
}),
body("password", "password does not Empty").not().isEmpty(),
body("password", "The minimum password length is 8 characters").isLength({
min: 8,
}),
];
module.exports = { registerValidator, loginValidator };