Skip to content

Commit

Permalink
fix: include fix for cannot change expiry to "never" (danny-avila#4293)
Browse files Browse the repository at this point in the history
  • Loading branch information
normunds-wipo committed Oct 1, 2024
1 parent 5e9ecc8 commit fb2b41f
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions api/server/services/UserService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit fb2b41f

Please # to comment.