Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/prevent-whitespace-saving.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

Prevent saving whitespace-only changes in nickname and bio and other fields in profile section
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { VisuallyHidden } from 'react-aria';
import { Controller, useFormContext } from 'react-hook-form';

import type { AccountProfileFormValues } from './getProfileInitialValues';
import { getProfileInitialValues } from './getProfileInitialValues';
import { useAccountProfileSettings } from './useAccountProfileSettings';
import { getUserEmailAddress } from '../../../../lib/getUserEmailAddress';
import UserStatusMenu from '../../../components/UserStatusMenu';
Expand Down Expand Up @@ -111,7 +112,7 @@ const AccountProfileForm = (props: AllHTMLAttributes<HTMLFormElement>): ReactEle

const handleSave = async ({ email, name, username, statusType, statusText, nickname, bio, customFields }: AccountProfileFormValues) => {
try {
await updateOwnBasicInfo({
const { user: updatedUser } = await updateOwnBasicInfo({
data: {
name,
...(user ? getUserEmailAddress(user) !== email && { email } : {}),
Expand All @@ -126,10 +127,9 @@ const AccountProfileForm = (props: AllHTMLAttributes<HTMLFormElement>): ReactEle

await updateAvatar();
dispatchToastMessage({ type: 'success', message: t('Profile_saved_successfully') });
reset(getProfileInitialValues(updatedUser));
} catch (error) {
dispatchToastMessage({ type: 'error', message: error });
} finally {
reset({ email, name, username, statusType, statusText, nickname, bio, customFields });
}
};

Expand Down
10 changes: 6 additions & 4 deletions apps/meteor/server/methods/saveUserProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,13 @@ async function saveUserProfile(
method: 'saveUserProfile',
});
}
if (settings.bio.length > MAX_BIO_LENGTH) {
const trimmedBio = settings.bio.trim();
if (trimmedBio.length > MAX_BIO_LENGTH) {
throw new Meteor.Error('error-bio-size-exceeded', `Bio size exceeds ${MAX_BIO_LENGTH} characters`, {
method: 'saveUserProfile',
});
}
await Users.setBio(user._id, settings.bio.trim());
await Users.setBio(user._id, trimmedBio);
}

if (user && (settings.nickname || settings.nickname === '')) {
Expand All @@ -104,12 +105,13 @@ async function saveUserProfile(
method: 'saveUserProfile',
});
}
if (settings.nickname.length > MAX_NICKNAME_LENGTH) {
const trimmedNickname = settings.nickname.trim();
if (trimmedNickname.length > MAX_NICKNAME_LENGTH) {
throw new Meteor.Error('error-nickname-size-exceeded', `Nickname size exceeds ${MAX_NICKNAME_LENGTH} characters`, {
method: 'saveUserProfile',
});
}
await Users.setNickname(user._id, settings.nickname.trim());
await Users.setNickname(user._id, trimmedNickname);
}

if (user && settings.email) {
Expand Down
Loading