Browse Source

Add middlewares

main
Haris Razis 4 years ago
parent
commit
6147288db7
No known key found for this signature in database GPG Key ID: 86A4D290ED03FAB4
  1. 24
      server/middlewares/middleware.js
  2. 0
      server/middlewares/validator.js

24
server/middlewares/middleware.js

@ -0,0 +1,24 @@
const {validationResult} = require('express-validator');
module.exports = {
handleErrors(route) {
return async (req, res, next) => {
const errors = validationResult(req);
if (!errors.isEmpty()) {
req.session.errors = errors.errors;
return res.redirect('/auth/' + route);
}
req.session.errors = {};
next();
}
},
handleErrorsPassport(req, res, route, info) {
req.session.errors = info;
return res.redirect('/auth/' + route);
},
requireAuth(req, res, next) {
if (!req.isAuthenticated())
return res.redirect('/auth/login');
next();
}
};

0
server/middlewares/validator.js

Loading…
Cancel
Save