Haris Razis
4 years ago
2 changed files with 24 additions and 0 deletions
@ -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(); |
|||
} |
|||
}; |
Loading…
Reference in new issue