christmas/middlewares/verifyAuth.js

16 lines
454 B
JavaScript
Raw Normal View History

2020-11-08 16:54:08 -05:00
const config = require('../config')
2018-11-20 14:19:58 -05:00
module.exports = options => {
return (req, res, next) => {
2020-11-08 16:54:08 -05:00
options = options || {}
2020-10-29 23:50:36 -04:00
let authed = false
try {
authed = req.isAuthenticated()
} catch {
return res.send('auth fail')
2018-11-20 14:19:58 -05:00
}
2020-10-29 23:50:36 -04:00
if (authed) return next()
2022-10-03 10:42:29 -04:00
if (_CC.config.guestPassword && req.query.pw === _CC.config.guestPassword) return next()
2020-10-29 23:50:36 -04:00
res.redirect(options.failureRedirect || config.defaultFailureRedirect)
2020-11-08 16:54:08 -05:00
}
}