From e080a376bf19d4dc095d0027b08cab07787b400d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Guti=C3=A9rrez?= <34506328+sg-gs@users.noreply.github.com> Date: Fri, 26 Apr 2024 12:34:30 +0200 Subject: [PATCH] fix(users): prevent crash on non-existent users for the auth middleware Prevent crashing when checking the property lastPasswordChangedAt for null users --- src/config/initializers/middleware.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/config/initializers/middleware.js b/src/config/initializers/middleware.js index 22c0e2c2..c7692825 100644 --- a/src/config/initializers/middleware.js +++ b/src/config/initializers/middleware.js @@ -166,6 +166,10 @@ module.exports = (App, Config) => { App.services.User.FindUserObjByEmail(email) .then((user) => { + if (!user) { + return done(new Error("User not found")); + } + const userWithoutLastPasswordChangedAt = user.lastPasswordChangedAt === null; const userWithLastPasswordChangedAtLowerThanToken = user.lastPasswordChangedAt &&