You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
698 B
JavaScript
20 lines
698 B
JavaScript
const {body} = require('express-validator')
|
|
const db = require('../../db')
|
|
|
|
const validators = module.exports = {}
|
|
|
|
validators.passwordRestrictions = body('password').isString().isLength({min: 8, max: 100}).withMessage('Password must be at least 8 characters')
|
|
|
|
validators.bothPasswordsMatch = body('password').custom((pass, {req})=>{
|
|
if(pass !== req.body.password2)
|
|
throw new Error('Passwords do not match')
|
|
return true
|
|
})
|
|
|
|
validators.emailRestrictions = body('email').isString().isEmail().withMessage('Email invalid')
|
|
|
|
validators.checkEmailNotUsed = body('email').custom(async email=>{
|
|
const user = await db.user.findByEmail(email)
|
|
if(user) throw new Error('Email already in use')
|
|
})
|