christmas/middlewares/verifyAuth.js
2022-10-03 10:42:29 -04:00

15 lines
454 B
JavaScript

const config = require('../config')
module.exports = options => {
return (req, res, next) => {
options = options || {}
let authed = false
try {
authed = req.isAuthenticated()
} catch {
return res.send('auth fail')
}
if (authed) return next()
if (_CC.config.guestPassword && req.query.pw === _CC.config.guestPassword) return next()
res.redirect(options.failureRedirect || config.defaultFailureRedirect)
}
}