From 35e611f113b92182a5cd5eafccf02164c9b09ad3 Mon Sep 17 00:00:00 2001 From: Linus Gasser Date: Tue, 30 Jan 2024 13:31:49 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=A4=20fix:=20Avatar=20Check=20in=20Use?= =?UTF-8?q?r=20Auth=20(#1677)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/strategies/process.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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;