diff --git a/controllers/auth.js b/controllers/auth.js index 0f241a320..4ac3d682b 100644 --- a/controllers/auth.js +++ b/controllers/auth.js @@ -131,6 +131,15 @@ exports.preauth = function (aReq, aRes, aNext) { }; +exports.errauth = function (aErr, aReq, aRes, aNext) { + if (aErr) { + console.error(aErr.status, aErr.message); + aRes.redirect(302, '/login?authfail'); + } else { + aNext(); + } +} + exports.auth = function (aReq, aRes, aNext) { function auth() { var authenticate = null; diff --git a/routes.js b/routes.js index 3d26c5355..bbebd8aa1 100644 --- a/routes.js +++ b/routes.js @@ -124,14 +124,10 @@ module.exports = function (aApp) { //--- Routes // Authentication routes - aApp.route('/auth/').post(authentication.preauth, hcaptcha.middleware.validate(SECRET, SITEKEY), - function (aErr, aReq, aRes, aNext) { - if (aErr) { - aRes.redirect(302, '/login?authfail'); - } else { - aNext(); - } - }, authentication.auth); + aApp.route('/auth/').post(authentication.preauth, + hcaptcha.middleware.validate(SECRET, SITEKEY), + authentication.errauth, + authentication.auth); aApp.route('/auth/:strategy').get(authentication.auth); aApp.route('/auth/:strategy/callback/:junk?').get(authentication.callback);