👤 fix: Avatar Check in User Auth (#1677)

This commit is contained in:
Linus Gasser 2024-01-30 13:31:49 +01:00 committed by GitHub
parent f7f7f929a0
commit 35e611f113
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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<void>}
@ -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;