fix: #12227, fix crash in redirect

This commit is contained in:
Barış Soner Uşaklı
2023-12-13 13:18:07 -05:00
parent e49ddaf815
commit 2dc1def51f
3 changed files with 16 additions and 14 deletions

View File

@@ -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();