{"record":{"id":"80f48546849b1baa","repo":"RocketChat/Rocket.Chat","slug":"error-could-not-save-identity-80f485","errorCode":"error-could-not-save-identity","errorMessage":"Could not save user identity","messagePattern":"Could not save user identity","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/meteor-methods/users/saveUserProfile.ts","lineNumber":79,"sourceCode":"\t});\n\n\tconst user = await Users.findOneById(this.userId);\n\n\tif (!user) {\n\t\tthrow new Meteor.Error('error-invalid-user', 'Invalid user', {\n\t\t\tmethod: 'saveUserProfile',\n\t\t});\n\t}\n\n\tif (settings.realname || settings.username) {\n\t\tif (\n\t\t\t!(await saveUserIdentity({\n\t\t\t\t_id: this.userId,\n\t\t\t\tname: settings.realname,\n\t\t\t\tusername: settings.username,\n\t\t\t}))\n\t\t) {\n\t\t\tthrow new Meteor.Error('error-could-not-save-identity', 'Could not save user identity', {\n\t\t\t\tmethod: 'saveUserProfile',\n\t\t\t});\n\t\t}\n\t}\n\n\tif (settings.statusType || settings.statusText != null) {\n\t\tawait setUserStatusMethod(user, settings.statusType as UserStatus, settings.statusText);\n\t}\n\n\tif (user && (settings.bio || settings.bio === '')) {\n\t\tif (typeof settings.bio !== 'string') {\n\t\t\tthrow new Meteor.Error('error-invalid-field', 'bio', {\n\t\t\t\tmethod: 'saveUserProfile',\n\t\t\t});\n\t\t}\n\t\tif (settings.bio.length > MAX_BIO_LENGTH) {\n\t\t\tthrow new Meteor.Error('error-bio-size-exceeded', `Bio size exceeds ${MAX_BIO_LENGTH} characters`, {\n\t\t\t\tmethod: 'saveUserProfile',","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/meteor-methods/users/saveUserProfile.ts#L61-L97","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nMeteor.call('saveUserProfile', { username: 'taken.name', realname: 'Ada' }, customFields);\n\n// after\nHTTP.get(`/api/v1/users.checkUsernameAvailability?username=${encodeURIComponent(username)}`, () => {\n  if (available) Meteor.call('saveUserProfile', { username, realname: 'Ada' }, customFields);\n  else showError('Username already in use');\n});","handlingStrategy":"validation","validationCode":"const USERNAME_RE = /^[a-zA-Z0-9-_.]+$/;\nconst okUsername = typeof username === 'string' && USERNAME_RE.test(username) && username.trim().length > 0;\n// optionally: HTTP.get(`/api/v1/users.checkUsernameAvailability?username=${encodeURIComponent(username)}`)\nconst okName = !requireNameForSignUp || (typeof realname === 'string' && realname.trim().length > 0);\nif (okUsername && okName) Meteor.call('saveUserProfile', settings, customFields);","typeGuard":"const isNonEmptyString = (v: unknown): v is string => typeof v === 'string' && v.trim().length > 0;","tryCatchPattern":"catch (err) {\n  if (err instanceof Meteor.Error && err.error === 'error-could-not-save-identity') {\n    showUsernameTaken(); // prompt for a new username\n  }\n}","preventionTips":["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"],"tags":["meteor","users","username","profile"],"backgroundTag":"username-already-in-use","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}