{"record":{"id":"e55718f8715390b8","repo":"Mintplex-Labs/anything-llm","slug":"username-cannot-be-longer-than-64-characters","errorCode":null,"errorMessage":"Username cannot be longer than 64 characters","messagePattern":"Username cannot be longer than 64 characters","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/models/user.js","lineNumber":39,"sourceCode":"    \"password\",\n    \"pfpFilename\",\n    \"role\",\n    \"suspended\",\n    \"dailyMessageLimit\",\n    \"bio\",\n  ],\n  validations: {\n    /**\n     * Unix-style username regex:\n     * - Must start with a lowercase letter\n     * - Can contain lowercase letters, digits, underscores, hyphens, @ signs, and periods\n     * - 2-64 characters long\n     */\n    username: (newValue = \"\") => {\n      try {\n        const username = String(newValue);\n        if (username.length > 64)\n          throw new Error(\"Username cannot be longer than 64 characters\");\n        if (username.length < 2)\n          throw new Error(\"Username must be at least 2 characters\");\n        if (!User.usernameRegex.test(username))\n          throw new Error(\n            \"Username must start with a lowercase letter and only contain lowercase letters, numbers, underscores, hyphens, and periods\"\n          );\n        return username;\n      } catch (e) {\n        throw new Error(e.message);\n      }\n    },\n    role: (role = \"default\") => {\n      const VALID_ROLES = [\"default\", \"admin\", \"manager\"];\n      if (!VALID_ROLES.includes(role)) {\n        throw new Error(\n          `Invalid role. Allowed roles are: ${VALID_ROLES.join(\", \")}`\n        );\n      }","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/models/user.js#L21-L57","documentation":"Thrown by User.validations.username when the stringified input exceeds 64 characters. The validator runs during User.create (line 122) and via the admin user-update endpoint (system.js:1252). It enforces the storage width of the users.username column and keeps names displayable.","triggerScenarios":"Creating a user (POST) or updating a username (PUT to the admin user endpoint) with a value longer than 64 characters.","commonSituations":"An external IdP/SSO provisioner passes a long email-style or DN-derived username. Bulk import from another system with lax limits. A script concatenates first/last names past the cap.","solutions":["Truncate or reformat the username to 64 characters or fewer before submitting.","In SSO provisioning, map the long external identifier to a short handle and store the original elsewhere.","Add a maxlength=64 attribute on the username input in the UI."],"exampleFix":"// before\nconst validated = User.validations.username(longExternalName);\n// after\nconst validated = User.validations.username(longExternalName.slice(0, 64));","handlingStrategy":"validation","validationCode":"if (typeof username === 'string' && username.length > 64) {\n  username = username.slice(0, 64);\n}","typeGuard":"const isUsernameLengthOk = (u) => typeof u === 'string' && u.length >= 2 && u.length <= 64;","tryCatchPattern":null,"preventionTips":["Set maxlength=64 on the username input.","In SSO provisioning, shorten long external identifiers to a handle."],"tags":["validation","user","length-limit"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}