{"record":{"id":"d5e1a38bb64c1cc4","repo":"RocketChat/Rocket.Chat","slug":"error-the-field-is-required-d5e1a3","errorCode":"error-the-field-is-required","errorMessage":"The field Name is required","messagePattern":"The field Name is required","errorType":"exception","errorClass":"MeteorError","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/lib/users/saveUser/validateUserData.ts","lineNumber":57,"sourceCode":"\tif (userData.roles) {\n\t\tconst newRoles = userData.roles.filter((roleId) => !existingRoles.includes(roleId));\n\t\tif (newRoles.length > 0) {\n\t\t\tthrow new MeteorError('error-action-not-allowed', 'The field Roles consist invalid role id', {\n\t\t\t\tmethod: 'insertOrUpdateUser',\n\t\t\t\taction: 'Assign_role',\n\t\t\t});\n\t\t}\n\t}\n\n\tif (userData.roles?.includes('admin') && !(await hasPermissionAsync(userId, 'assign-admin-role'))) {\n\t\tthrow new MeteorError('error-action-not-allowed', 'Assigning admin is not allowed', {\n\t\t\tmethod: 'insertOrUpdateUser',\n\t\t\taction: 'Assign_admin',\n\t\t});\n\t}\n\n\tif (settings.get('Accounts_RequireNameForSignUp') && !isUpdateUserData(userData) && !trim(userData.name)) {\n\t\tthrow new MeteorError('error-the-field-is-required', 'The field Name is required', {\n\t\t\tmethod: 'insertOrUpdateUser',\n\t\t\tfield: 'Name',\n\t\t});\n\t}\n\n\tif (!isUpdateUserData(userData) && !trim(userData.username)) {\n\t\tthrow new MeteorError('error-the-field-is-required', 'The field Username is required', {\n\t\t\tmethod: 'insertOrUpdateUser',\n\t\t\tfield: 'Username',\n\t\t});\n\t}\n\n\tlet nameValidation;\n\n\ttry {\n\t\tnameValidation = new RegExp(`^${settings.get('UTF8_User_Names_Validation')}$`);\n\t} catch (e) {\n\t\tnameValidation = new RegExp('^[0-9a-zA-Z-_.]+$');","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/lib/users/saveUser/validateUserData.ts#L39-L75","documentation":"Thrown by validateUserData() on CREATE when the server setting Accounts_RequireNameForSignUp is enabled and the submitted name is empty after trimming. The check only applies to creation (isUpdateUserData false), so updates never need a name even when the setting is on. Code is error-the-field-is-required with field 'Name' in the error details.","triggerScenarios":"POST /api/v1/users.create with name missing, empty string, or whitespace-only while the workspace requires names; automated provisioning that only supplies username/email/password; a mobile client whose optional name field was left blank.","commonSituations":"Workspace admin enabled 'Accounts_RequireNameForSignUp' after scripts were written; LDAP/SSO provisioning code that never populated name; UI forms that submit the field as '' instead of omitting it.","solutions":["Include a non-blank name in the create payload (trim(name) must be non-empty).","If nameless users are acceptable, disable Accounts_RequireNameForSignUp in Administration -> Accounts -> Registration.","For provisioning pipelines, default name to the username or email local-part when no display name is available."],"exampleFix":"// before\nawait POST '/api/v1/users.create', { username: 'alice', email: 'a@b.c', password: 'pw' }); // throws when setting on\n\n// after\nawait POST '/api/v1/users.create', { username: 'alice', email: 'a@b.c', password: 'pw', name: 'Alice' });","handlingStrategy":"validation","validationCode":"const requireName = settings.get('Accounts_RequireNameForSignUp'); // or read public settings via GET /api/v1/settings.public\nif (requireName && !payload.name?.trim()) {\n  throw new Error('Name is required on this workspace');\n}","typeGuard":"const hasNonEmptyName = (p: { name?: string }) => !!p.name && p.name.trim().length > 0;","tryCatchPattern":"catch (e) {\n  if (e.error === 'error-the-field-is-required' && e.details?.field === 'Name') {\n    // prompt the user for a display name and resubmit\n  }\n}","preventionTips":["Make the name input required client-side when the workspace setting is on.","Default name to username or email local-part in provisioning scripts.","Re-check workspace settings after admin configuration changes."],"tags":["users","validation","required-field","registration","save-user"],"backgroundTag":"missing-required-argument","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","contentChangedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}