From 1ced3eb9f1fbafd210e22bd92305740744b43320 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Tue, 11 Jun 2024 18:25:59 -0400 Subject: [PATCH 1/2] don't crash on missing user --- src/controllers/accounts/follow.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/controllers/accounts/follow.js b/src/controllers/accounts/follow.js index 58dba7f3c0..7a28374582 100644 --- a/src/controllers/accounts/follow.js +++ b/src/controllers/accounts/follow.js @@ -14,8 +14,11 @@ followController.getFollowers = async function (req, res, next) { await getFollow('account/followers', 'followers', req, res, next); }; -async function getFollow(tpl, name, req, res) { +async function getFollow(tpl, name, req, res, next) { const { userData: payload } = res.locals; + if (!payload) { + return next(); + } const { username, userslug, followerCount, followingCount, } = payload; From 35710e655130aaf3e9e77c714eca6fd8b4451c27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Tue, 11 Jun 2024 18:28:10 -0400 Subject: [PATCH 2/2] catch all deleted/missing and 404 --- src/middleware/user.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/middleware/user.js b/src/middleware/user.js index 82621bf71e..3b7c1168db 100644 --- a/src/middleware/user.js +++ b/src/middleware/user.js @@ -260,6 +260,9 @@ module.exports = function (middleware) { } res.locals.userData = await accountHelpers.getUserDataByUserSlug(req.params.userslug, req.uid, req.query); + if (!res.locals.userData) { + return next('route'); + } next(); };