Skip to content

Commit

Permalink
Scoot some code around
Browse files Browse the repository at this point in the history
  • Loading branch information
Martii committed Dec 8, 2021
1 parent 77b7fef commit 99a4983
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
9 changes: 9 additions & 0 deletions controllers/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 4 additions & 8 deletions routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 99a4983

Please sign in to comment.