{"record":{"id":"4196e9fafd075fe6","repo":"Mintplex-Labs/anything-llm","slug":"invalid-role-allowed-roles-are-valid-roles-joi","errorCode":null,"errorMessage":"Invalid role. Allowed roles are: ${VALID_ROLES.join(\", \")}","messagePattern":"Invalid role\\. Allowed roles are: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/models/user.js","lineNumber":54,"sourceCode":"      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      }\n      return String(role);\n    },\n    dailyMessageLimit: (dailyMessageLimit = null) => {\n      if (dailyMessageLimit === null) return null;\n      const limit = Number(dailyMessageLimit);\n      if (isNaN(limit) || limit < 1) {\n        throw new Error(\n          \"Daily message limit must be null or a number greater than or equal to 1\"\n        );\n      }\n      return limit;\n    },\n    bio: (bio = \"\") => {\n      if (!bio || typeof bio !== \"string\") return \"\";\n      if (bio.length > 1000)","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/models/user.js#L36-L72","documentation":"Thrown by User.validations.role when the supplied role is not in the hard-coded set ['default','admin','manager']. The validator is called during User.create (line 130). The error message is a template literal that interpolates the allowed list, so the thrown string reads 'Invalid role. Allowed roles are: default, admin, manager'.","triggerScenarios":"Creating a user with a role value outside the allowed set, e.g. 'superuser', 'owner', 'guest', or a typo like 'admn'.","commonSituations":"API client sends a role from a different auth vocabulary. A newer/older frontend version uses a role name not present in this backend. Migration/import carrying a legacy role string.","solutions":["Use one of: 'default', 'admin', or 'manager'.","Map any external/legacy role to the closest allowed value before calling User.create.","Confirm frontend and backend role enums stay in sync."],"exampleFix":"// before\nUser.create({ username, password, role: 'superuser' });\n// after\nUser.create({ username, password, role: 'admin' });","handlingStrategy":"type-guard","validationCode":"const ALLOWED_ROLES = ['default', 'admin', 'manager'];\nif (!ALLOWED_ROLES.includes(role)) role = 'default';","typeGuard":"const isValidRole = (r) => typeof r === 'string' && ['default', 'admin', 'manager'].includes(r);","tryCatchPattern":null,"preventionTips":["Share a single role enum between frontend and backend.","Default unknown roles to 'default' rather than rejecting, where the UX allows."],"tags":["validation","user","role","authorization"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}