diff --git a/api/strategies/process.js b/api/strategies/process.js index f5a12a26a2..570637eecd 100644 --- a/api/strategies/process.js +++ b/api/strategies/process.js @@ -7,7 +7,7 @@ const User = require('~/models/User'); * '?manual=true', it updates the user's avatar with the provided URL. For local file storage, it directly updates * the avatar URL, while for other storage types, it processes the avatar URL using the specified file strategy. * - * @param {User} oldUser - The existing user object that needs to be updated. Expected to have an 'avatar' property. + * @param {User} oldUser - The existing user object that needs to be updated. * @param {string} avatarUrl - The new avatar URL to be set for the user. * * @returns {Promise} @@ -19,10 +19,10 @@ const handleExistingUser = async (oldUser, avatarUrl) => { const fileStrategy = process.env.CDN_PROVIDER; const isLocal = fileStrategy === FileSources.local; - if (isLocal && !oldUser.avatar.includes('?manual=true')) { + if (isLocal && (oldUser.avatar === null || !oldUser.avatar.includes('?manual=true'))) { oldUser.avatar = avatarUrl; await oldUser.save(); - } else if (!isLocal && !oldUser.avatar.includes('?manual=true')) { + } else if (!isLocal && (oldUser.avatar === null || !oldUser.avatar.includes('?manual=true'))) { const userId = oldUser._id; const newavatarUrl = await uploadAvatar({ userId, input: avatarUrl, fileStrategy }); oldUser.avatar = newavatarUrl;