christmas/middlewares/verifyAuth.js

14 lines
372 B
JavaScript
Raw Normal View History

2018-11-20 11:19:58 -08:00
const config = require('../config');
module.exports = options => {
return (req, res, next) => {
options = options ? options : {};
2020-10-29 20:50:36 -07:00
let authed = false
try {
authed = req.isAuthenticated()
} catch {
return res.send('auth fail')
2018-11-20 11:19:58 -08:00
}
2020-10-29 20:50:36 -07:00
if (authed) return next()
res.redirect(options.failureRedirect || config.defaultFailureRedirect)
2018-11-20 11:19:58 -08:00
};
}