From fb2b41f214a7b3d4ef3d89e2c062929a74ae0230 Mon Sep 17 00:00:00 2001 From: KALNBERZINS Normunds Date: Tue, 1 Oct 2024 09:26:13 +0200 Subject: [PATCH] fix: include fix for cannot change expiry to "never" (#4293) --- api/server/services/UserService.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/api/server/services/UserService.js b/api/server/services/UserService.js index 9e6ef7b8746..fb36ac1cb8a 100644 --- a/api/server/services/UserService.js +++ b/api/server/services/UserService.js @@ -144,13 +144,15 @@ const updateUserKey = async ({ userId, name, value, expiresAt = null }) => { name, value: encryptedValue, }; - - // Only add expiresAt to the update object if it's not null + const updateQuery = { $set: updateObject }; + // add expiresAt to the update object if it's not null if (expiresAt) { updateObject.expiresAt = new Date(expiresAt); + } else { + // else unset if already present + updateQuery.$unset = { expiresAt }; } - - return await Key.findOneAndUpdate({ userId, name }, updateObject, { + return await Key.findOneAndUpdate({ userId, name }, updateQuery, { upsert: true, new: true, }).lean();