{"record":{"id":"1b5983f81310bb28","repo":"RocketChat/Rocket.Chat","slug":"error-field-unavailable-1b5983","errorCode":"error-field-unavailable","errorMessage":"<strong>${_.escape(username)}</strong> is already in use :(","messagePattern":"<strong>(.+?)</strong> is already in use :\\(","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/lib/users/setUsername.ts","lineNumber":64,"sourceCode":"\t}\n\n\tif (user.username && !settings.get('Accounts_AllowUsernameChange')) {\n\t\tthrow new Meteor.Error('error-not-allowed', 'Not allowed');\n\t}\n\n\tif (user.username === username || (user.username && user.username.toLowerCase() === username.toLowerCase())) {\n\t\treturn;\n\t}\n\n\tif (!validateUsername(username)) {\n\t\tthrow new Meteor.Error(\n\t\t\t'username-invalid',\n\t\t\t`${_.escape(username)} is not a valid username, use only letters, numbers, dots, hyphens and underscores`,\n\t\t);\n\t}\n\n\tif (!(await checkUsernameAvailability(username))) {\n\t\tthrow new Meteor.Error('error-field-unavailable', `<strong>${_.escape(username)}</strong> is already in use :(`, {\n\t\t\tmethod: 'setUsername',\n\t\t\tfield: username,\n\t\t});\n\t}\n\n\tif (!(await saveUserIdentity({ _id: user._id, username }))) {\n\t\tthrow new Meteor.Error('error-could-not-change-username', 'Could not change username', {\n\t\t\tmethod: 'setUsername',\n\t\t});\n\t}\n\n\tif (!user.username) {\n\t\tawait joinDefaultChannels(user._id, joinDefaultChannelsSilenced);\n\t\tsetImmediate(async () => callbacks.run('afterCreateUser', user));\n\t}\n\n\tvoid notifyOnUserChange({ clientAction: 'updated', id: user._id, diff: { username } });\n};","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/lib/users/setUsername.ts#L46-L82","documentation":"checkUsernameAvailability() returned false: either another user already holds the name case-insensitively (Users.findOneByUsernameIgnoringCase) or a team is named the same (Team.getOneByName). Note the sibling case: names on Accounts_BlockedUsernameList (plus 'all'/'here') or Accounts_SystemBlockedUsernameList throw error-blocked-username instead — this error specifically means 'someone else owns it'.","triggerScenarios":"Submitting a username identical (ignoring case) to an existing user's or a team's name; casing-only changes to a name owned by someone else; a registration callback (checkUsernameAvailabilityCallback) rejecting the name.","commonSituations":"Self-service signup collisions ('mike', 'admin', 'john.smith'); users and teams sharing one namespace so a team name blocks a user name; migrations importing users with conflicting handles.","solutions":["Choose a different name (the UI should suggest alternatives like name+number)","Pre-check with checkUsernameAvailabilityWithValidation while the user types to fail fast","If the name belongs to a deactivated/old account, an admin must rename or delete that account to free the name"],"exampleFix":"// before\nawait setUsernameWithValidation(userId, 'john'); // error-field-unavailable\n\n// after\nif (!(await checkUsernameAvailability('john'))) {\n  throw new Meteor.Error('error-field-unavailable', 'john is already in use');\n}\nawait setUsernameWithValidation(userId, 'john');","handlingStrategy":"validation","validationCode":"import { checkUsernameAvailabilityWithValidation } from './checkUsernameAvailability';\n\nconst available = await checkUsernameAvailabilityWithValidation(userId, username);\nif (!available) {\n  // prompt for a different name before calling the save method\n}","typeGuard":null,"tryCatchPattern":"try {\n  await setUsernameWithValidation(userId, username);\n} catch (error) {\n  if (error instanceof Meteor.Error && error.error === 'error-field-unavailable') {\n    const taken = (error.details as { field?: string } | undefined)?.field;\n    // mark the input as taken and keep the form open\n  } else {\n    throw error;\n  }\n}","preventionTips":["Treat usernames and team names as one namespace when checking availability","Compare case-insensitively on the client too — 'John' vs 'john' collides","Re-check availability at submit time, not only while typing"],"tags":["username","availability","duplicate","meteor"],"backgroundTag":"duplicate-username","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}