Created
October 7, 2019 18:24
-
-
Save artemis15/d93b4cc2b302432caf9925fcdcf112f6 to your computer and use it in GitHub Desktop.
JWT validation file foe middleware
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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