fix: move authenticateRequest before interstitial and maintenance mode middlewares, allowed plugins to disable authentication on certain routes

fixes #10112
isekai-main
Julian Lam 3 years ago
parent f1aa5f7d18
commit d89fc44c03

@ -2,6 +2,8 @@
const winston = require('winston'); const winston = require('winston');
const passport = require('passport'); const passport = require('passport');
const nconf = require('nconf');
const path = require('path');
const util = require('util'); const util = require('util');
const user = require('../user'); const user = require('../user');
@ -81,6 +83,20 @@ module.exports = function (middleware) {
} }
middleware.authenticateRequest = helpers.try(async (req, res, next) => { middleware.authenticateRequest = helpers.try(async (req, res, next) => {
const { skip } = await plugins.hooks.fire('filter:middleware.authenticate', {
skip: {
// get: [],
post: ['/api/v3/utilities/login'],
// etc...
},
});
const mountedPath = path.join(req.baseUrl, req.path).replace(nconf.get('relative_path'), '');
const method = req.method.toLowerCase();
if (skip[method] && skip[method].includes(mountedPath)) {
return next();
}
if (!await authenticate(req, res)) { if (!await authenticate(req, res)) {
return; return;
} }

@ -15,9 +15,9 @@ function _handleArgs(middleware, middlewares, controller) {
} }
middlewares = [ middlewares = [
middleware.authenticateRequest,
middleware.maintenanceMode, middleware.maintenanceMode,
middleware.registrationComplete, middleware.registrationComplete,
middleware.authenticateRequest,
middleware.pluginHooks, middleware.pluginHooks,
...middlewares, ...middlewares,
]; ];

Loading…
Cancel
Save