RocketChat/Rocket.Chat · error · Meteor.Error
error-could-not-save-identity
error-could-not-save-identity
Error message
Could not save user identity
What it means
Thrown when saveUserIdentity() returns false while saving name/username inside saveUserProfile. saveUserIdentity (server/lib/users/saveUserIdentity.ts) returns false when: the new username fails validateUsername, is not available (taken, even case-insensitively), is on the Accounts_SystemBlockedUsernameList, the user record disappeared, or setRealName returned falsy (empty realname while Accounts_RequireNameForSignUp is enabled).
Source
Thrown at apps/meteor/server/meteor-methods/users/saveUserProfile.ts:79
});
const user = await Users.findOneById(this.userId);
if (!user) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', {
method: 'saveUserProfile',
});
}
if (settings.realname || settings.username) {
if (
!(await saveUserIdentity({
_id: this.userId,
name: settings.realname,
username: settings.username,
}))
) {
throw new Meteor.Error('error-could-not-save-identity', 'Could not save user identity', {
method: 'saveUserProfile',
});
}
}
if (settings.statusType || settings.statusText != null) {
await setUserStatusMethod(user, settings.statusType as UserStatus, settings.statusText);
}
if (user && (settings.bio || settings.bio === '')) {
if (typeof settings.bio !== 'string') {
throw new Meteor.Error('error-invalid-field', 'bio', {
method: 'saveUserProfile',
});
}
if (settings.bio.length > MAX_BIO_LENGTH) {
throw new Meteor.Error('error-bio-size-exceeded', `Bio size exceeds ${MAX_BIO_LENGTH} characters`, {
method: 'saveUserProfile',View on GitHub (pinned to b2c16d5842)
Solutions
- Pre-check the username: GET /api/v1/users.checkUsernameAvailability?username=<name> (or Meteor username suggestion endpoint) before submitting the profile form
- Ensure realname is a non-empty trimmed string when Accounts_RequireNameForSignUp is enabled
- Verify the requested username is not in Accounts_SystemBlockedUsernameList and matches /^[a-zA-Z0-9-_.]+$/
- Catch error-could-not-save-identity in the UI and prompt for a different username/name
Example fix
// before
Meteor.call('saveUserProfile', { username: 'taken.name', realname: 'Ada' }, customFields);
// after
HTTP.get(`/api/v1/users.checkUsernameAvailability?username=${encodeURIComponent(username)}`, () => {
if (available) Meteor.call('saveUserProfile', { username, realname: 'Ada' }, customFields);
else showError('Username already in use');
}); Defensive patterns
Strategy: validation
Validate before calling
const USERNAME_RE = /^[a-zA-Z0-9-_.]+$/;
const okUsername = typeof username === 'string' && USERNAME_RE.test(username) && username.trim().length > 0;
// optionally: HTTP.get(`/api/v1/users.checkUsernameAvailability?username=${encodeURIComponent(username)}`)
const okName = !requireNameForSignUp || (typeof realname === 'string' && realname.trim().length > 0);
if (okUsername && okName) Meteor.call('saveUserProfile', settings, customFields); Type guard
const isNonEmptyString = (v: unknown): v is string => typeof v === 'string' && v.trim().length > 0;
Try / catch
catch (err) {
if (err instanceof Meteor.Error && err.error === 'error-could-not-save-identity') {
showUsernameTaken(); // prompt for a new username
}
} Prevention
- Check username availability as the user types (debounced) instead of only at submit
- Never send realname: '' on workspaces where Accounts_RequireNameForSignUp is true
- Keep the username regex client-side in sync with the server's allowed characters
When it happens
Trigger: saveUserProfile called with settings.realname or settings.username where the requested username is already used (checkUsernameAvailability fails), matches Accounts_SystemBlockedUsernameList, fails the username format check, or realname is empty/string-whitespace while Accounts_RequireNameForSignUp=true.
Common situations: Profile form lets users pick a username another account took in the meantime; admin blocked names like 'admin' via Accounts_SystemBlockedUsernameList; name-required workspaces where the client sends realname: '' to clear the display name.
Related errors
- error-invalid-user
- User must have a username to be banned from the room
- User not found
- error-invalid-username
- error-invalid-user
AI-assisted analysis of RocketChat/Rocket.Chat@b2c16d5842 (2026-08-18).
Data as JSON: /api/errors/80f48546849b1baa.
Report an issue: GitHub.