Skip to content

Instantly share code, notes, and snippets.

@artemis15
Created October 7, 2019 18:24
Show Gist options
  • Save artemis15/d93b4cc2b302432caf9925fcdcf112f6 to your computer and use it in GitHub Desktop.
Save artemis15/d93b4cc2b302432caf9925fcdcf112f6 to your computer and use it in GitHub Desktop.
JWT validation file foe middleware
const {body} = require('express-validator/check');
const validateRegistrationBody = () => {
return [
body('name')
.exists()
.withMessage('name field is required')
.isLength({min:3})
.withMessage('name must be greater than 3 letters'),
body('email').exists()
.withMessage('email field is required')
.isEmail()
.withMessage('Email is invalid'),
body('password')
.exists()
.withMessage('password field is required')
.isLength({min : 8,max: 12})
.withMessage('password must be in between 8 to 12 characters long')
]
}
const validateLoginBody = () => {
return [
body('email').exists()
.withMessage('email field is required')
.isEmail()
.withMessage('Email is invalid'),
body('password')
.exists()
.withMessage('password field is required')
.isLength({min : 8,max: 12})
.withMessage('password must be in between 8 to 12 characters long')
]
}
module.exports = {
validateRegistrationBody : validateRegistrationBody,
validateLoginBody : validateLoginBody
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment