diff --git a/server/middlewares/middleware.js b/server/middlewares/middleware.js new file mode 100644 index 0000000..3436510 --- /dev/null +++ b/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(); + } +}; \ No newline at end of file diff --git a/server/middlewares/validator.js b/server/middlewares/validator.js new file mode 100644 index 0000000..e69de29