You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
709 B
24 lines
709 B
4 years ago
|
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();
|
||
|
}
|
||
|
};
|