mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 08:50:15 +01:00
🛠️ fix: Remove expiresAt field when setting expiry to "never" (#4294)
This commit is contained in:
parent
ee5b96a7c8
commit
77bcb80e00
1 changed files with 8 additions and 6 deletions
|
|
@ -103,10 +103,10 @@ const getUserKeyExpiry = async ({ userId, name }) => {
|
||||||
* @param {string} params.userId - The unique identifier for the user.
|
* @param {string} params.userId - The unique identifier for the user.
|
||||||
* @param {string} params.name - The name associated with the key.
|
* @param {string} params.name - The name associated with the key.
|
||||||
* @param {string} params.value - The value to be encrypted and stored as the key's value.
|
* @param {string} params.value - The value to be encrypted and stored as the key's value.
|
||||||
* @param {Date} params.expiresAt - The expiry date for the key.
|
* @param {Date} params.expiresAt - The expiry date for the key [optional]
|
||||||
* @returns {Promise<Object>} The updated or newly inserted key document.
|
* @returns {Promise<Object>} The updated or newly inserted key document.
|
||||||
* @description This function either updates an existing user key or inserts a new one into the database,
|
* @description This function either updates an existing user key or inserts a new one into the database,
|
||||||
* after encrypting the provided value. It sets the provided expiry date for the key.
|
* after encrypting the provided value. It sets the provided expiry date for the key (or unsets for no expiry).
|
||||||
*/
|
*/
|
||||||
const updateUserKey = async ({ userId, name, value, expiresAt = null }) => {
|
const updateUserKey = async ({ userId, name, value, expiresAt = null }) => {
|
||||||
const encryptedValue = await encrypt(value);
|
const encryptedValue = await encrypt(value);
|
||||||
|
|
@ -115,13 +115,15 @@ const updateUserKey = async ({ userId, name, value, expiresAt = null }) => {
|
||||||
name,
|
name,
|
||||||
value: encryptedValue,
|
value: encryptedValue,
|
||||||
};
|
};
|
||||||
|
const updateQuery = { $set: updateObject };
|
||||||
// Only add expiresAt to the update object if it's not null
|
// add expiresAt to the update object if it's not null
|
||||||
if (expiresAt) {
|
if (expiresAt) {
|
||||||
updateObject.expiresAt = new Date(expiresAt);
|
updateObject.expiresAt = new Date(expiresAt);
|
||||||
|
} else {
|
||||||
|
// make sure to remove if already present
|
||||||
|
updateQuery.$unset = { expiresAt };
|
||||||
}
|
}
|
||||||
|
return await Key.findOneAndUpdate({ userId, name }, updateQuery, {
|
||||||
return await Key.findOneAndUpdate({ userId, name }, updateObject, {
|
|
||||||
upsert: true,
|
upsert: true,
|
||||||
new: true,
|
new: true,
|
||||||
}).lean();
|
}).lean();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue