Comments (13)
@Mustafiz04 i would like to work on this issue.
from bunk-manager-mern.
Yes you can @Muditxofficial
I am assigning to you.
from bunk-manager-mern.
@Mustafiz04 What should i do about error messages should i just console log it. Also, i have to use express-validator right just to confirm as i need to install it .
from bunk-manager-mern.
@Muditxofficial return the message in similar way we return the data that can be used by frontend to display that message.
Yes, use express-validator.
https://express-validator.github.io/docs/check-api.html
for reference
don't forget to use it as middleware.
from bunk-manager-mern.
@Muditxofficial How you work going on ??
from bunk-manager-mern.
@Mustafiz04 I have started doing login but on which route should i check it.
http://localhost:3000/api/auth/login does not work
from bunk-manager-mern.
Sorry for late.
Wait I am explaining you.
from bunk-manager-mern.
Validator file
const { check, validationResult } = require('express-validator');
exports.validateSignupRequest = [
check('name').notEmpty().withMessage("First name is required"),
check('email').isEmail().withMessage("Email is required"),
check('password').isLength({min : 6}).withMessage("Password must be atleast 6 character long")
];
exports.isRequestValidated = (req, res, next) => {
const errors = validationResult(req);
if( errors.array().length > 0 ){
return res.status(400).json({
errors : errors.array()[0]
})
}
next();
}
in route file
const { validateSignupRequest, isRequestValidated } = require('./../../middleware/validator/auth');
router.post('/signup', validateSignupRequest, isRequestValidated, signup );
Apply to all route with take input from frontend.
from bunk-manager-mern.
@Mustafiz04 Is there a way to check if my implementation is right using postman ?
i found two different url localhost:3000/user/signup and localhost:3000/api/auth/new/signup
from bunk-manager-mern.
yes you can check every API on postman.
localhost:3000/api/auth/new/signup
this is correct
I give only example how to write validator and apply that to route as middleware.
Follow that ways, create and apply middleware to every route.
from bunk-manager-mern.
When will you complete this task because it take lots of time.
from bunk-manager-mern.
Validator
const { check, validationResult } = require('express-validator');
exports.validateSignupRequest = [
check('name').notEmpty().withMessage("First name is required"),
check('email').isEmail().withMessage("Email is required"),
check('password').isLength({min : 6}).withMessage("Password must be atleast 6 character long")
];
exports.validateLogin = [
check('email').isEmail().withMessage("Email is required"),
check('password').isLength({min : 6}).withMessage("Password must be atleast 6 character long")
]
exports.isRequestValidated = (req, res, next) => {
const errors = validationResult(req);
if( errors.array().length > 0 ){
console.log(errors.array()[0])
return res.status(400).json({
errors : errors.array()[0]
})
}
next();
}
Routes
const { validateSignupRequest, isRequestValidated, validateLogin } = require("../middlewares/validators")
router.post('/api/auth/login',isRequestValidated,validateLogin,loginUser);
router.post('/api/auth/new/signup',validateSignupRequest,isRequestValidated,createUser);
Is it ok or should i add something?
from bunk-manager-mern.
correct but isRequestValidated
always after validator function like validateLogin
from bunk-manager-mern.
Related Issues (20)
- Design - Login Page - Mobile HOT 1
- Create the Landing Page in React. HOT 10
- Design - Sign Up Page - Web and Mobile HOT 1
- UI Design for AboutsUs page HOT 3
- Design - Today Page - Web and Mobile HOT 1
- Add the floating animaton in the svg of the home page. HOT 8
- Readme file enhancement HOT 3
- Create the Login page in React HOT 18
- Create the Sign up page in React HOT 8
- Create the Today page in React HOT 6
- Create the Subject details page in React HOT 24
- CRON JOB FROM ATTENDANCE | BACKEND HOT 8
- BACKEND OPTIMISATION HOT 3
- Failed to find .env file at path: ./configs/dev.env HOT 4
- Frontend: Add a 404 NOT FOUND page HOT 3
- Setting up Eslint and making the code prettier HOT 10
- Google Sign In Not Working HOT 8
- Clean the code. HOT 1
- Landing page as per new designs
- Can you give me an account to log in the app on heroku? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bunk-manager-mern.