mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
fix: #12227, fix crash in redirect
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
const user = require('../user');
|
||||
const plugins = require('../plugins');
|
||||
const helpers = require('./helpers');
|
||||
|
||||
@@ -27,17 +26,5 @@ async function doBuildHeader(req, res) {
|
||||
}
|
||||
|
||||
await plugins.hooks.fire('filter:middleware.buildHeader', { req: req, locals: res.locals });
|
||||
const [config, canLoginIfBanned] = await Promise.all([
|
||||
controllers.api.loadConfig(req),
|
||||
user.bans.canLoginIfBanned(req.uid),
|
||||
]);
|
||||
|
||||
if (!canLoginIfBanned && req.loggedIn) {
|
||||
req.logout(() => {
|
||||
res.redirect('/');
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
res.locals.config = config;
|
||||
res.locals.config = await controllers.api.loadConfig(req);
|
||||
}
|
||||
|
||||
@@ -221,6 +221,20 @@ module.exports = function (middleware) {
|
||||
controllers.helpers.redirect(res, path);
|
||||
});
|
||||
|
||||
middleware.redirectToHomeIfBanned = helpers.try(async (req, res, next) => {
|
||||
if (req.loggedIn) {
|
||||
const canLoginIfBanned = await user.bans.canLoginIfBanned(req.uid);
|
||||
if (!canLoginIfBanned) {
|
||||
req.logout(() => {
|
||||
res.redirect('/');
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
|
||||
middleware.requireUser = function (req, res, next) {
|
||||
if (req.loggedIn) {
|
||||
return next();
|
||||
|
||||
@@ -18,6 +18,7 @@ helpers.setupPageRoute = function (...args) {
|
||||
middlewares = [
|
||||
middleware.applyBlacklist,
|
||||
middleware.authenticateRequest,
|
||||
middleware.redirectToHomeIfBanned,
|
||||
middleware.maintenanceMode,
|
||||
middleware.registrationComplete,
|
||||
middleware.pluginHooks,
|
||||
|
||||
Reference in New Issue
Block a user