{"record":{"id":"02a9e2fb35cf6ec6","repo":"Mintplex-Labs/anything-llm","slug":"failed-to-enable-multi-user-mode","errorCode":null,"errorMessage":"Failed to enable multi-user mode.","messagePattern":"Failed to enable multi-user mode\\.","errorType":"http","errorClass":null,"httpStatus":400,"severity":"error","filePath":"server/endpoints/system.js","lineNumber":678,"sourceCode":"        if (response.locals.multiUserMode) {\n          response.status(200).json({\n            success: false,\n            error: \"Multi-user mode is already enabled.\",\n          });\n          return;\n        }\n\n        const { username, password } = reqBody(request);\n        const { user, error } = await User.create({\n          username,\n          password,\n          role: ROLES.admin,\n        });\n\n        if (error || !user) {\n          response.status(400).json({\n            success: false,\n            error: error || \"Failed to enable multi-user mode.\",\n          });\n          return;\n        }\n\n        await SystemSettings._updateSettings({\n          multi_user_mode: true,\n        });\n        await BrowserExtensionApiKey.migrateApiKeysToMultiUser(user.id);\n        await Memory.migrateToMultiUser(user.id);\n        await WorkspaceChats.migrateToMultiUser(user.id);\n        await WorkspaceThread.migrateToMultiUser(user.id);\n        await WorkspaceParsedFiles.migrateToMultiUser(user.id);\n        await MobileDevice.migrateDevicesToMultiUser(user.id);\n        await SlashCommandPresets.migrateToMultiUser(user.id);\n        await AgentSkillWhitelist.clearSingleUserWhitelist();\n        await updateENV(\n          {\n            JWTSecret: process.env.JWT_SECRET || v4(),","sourceCodeStart":660,"sourceCodeEnd":696,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/20f6d3546c1938bfea1ad304f58a592dddcc5948/server/endpoints/system.js#L660-L696","documentation":"400 from POST /system/enable-multi-user. The handler creates the first admin user via User.create; on failure it echoes that error, falling back to this generic string only when no specific error was produced. Typical User.create failures: password complexity (joi-password-complexity, min 8 chars via PASSWORDMINCHAR), invalid username format (must start with a lowercase letter; only lowercase letters, digits, and . _ @ - allowed; 2–64 chars), or a duplicate username (prisma P2002 mapped to 'A user with that ... already exists').","triggerScenarios":"First-boot setup POSTing {username:'Admin', password:'password'} — uppercase/short username or weak password; re-running setup after a partial failure left a user row behind; database rejecting the insert.","commonSituations":"Rushing onboarding with a throwaway password; corporate email-style usernames containing capital letters or spaces; retrying setup after a timeout that actually created the user.","solutions":["Use a password of at least 8 characters (or whatever PASSWORDMINCHAR demands on this deployment)","Use a username matching ^[a-z][a-z0-9._@-]{1,63}$ — starts lowercase, no spaces or capitals","If setup previously half-completed, remove the leftover admin user and retry; on success the endpoint flips multi_user_mode on and migrates single-user data"],"exampleFix":"// before\nawait api.post('/system/enable-multi-user', {\n  username: 'Admin', password: 'password'\n}); // 400\n\n// after\nawait api.post('/system/enable-multi-user', {\n  username: 'admin', password: 'at-least-8-chars'\n});","handlingStrategy":"validation","validationCode":"// Mirror the server's rules before calling /system/enable-multi-user\nconst USERNAME_RE = /^[a-z][a-z0-9._@-]{1,63}$/;\nfunction isFirstAdminPayload({ username, password }) {\n  return USERNAME_RE.test(String(username)) && String(password).length >= 8;\n}\nif (!isFirstAdminPayload(payload)) throw new Error('Username must be lowercase-format; password >= 8 chars');","typeGuard":"function isFirstAdminInput(v) {\n  return !!v && typeof v.username === 'string' && typeof v.password === 'string' &&\n    /^[a-z][a-z0-9._@-]{1,63}$/.test(v.username);\n}","tryCatchPattern":null,"preventionTips":["Validate the username format client-side before first-boot setup","Read the returned error string — it names the real cause (complexity, username format, duplicate)","If setup timed out, check whether the admin user was already created before retrying"],"tags":["multi-user","setup","validation","user-creation"],"backgroundTag":"user-creation-failed","analyzedSha":"20f6d3546c1938bfea1ad304f58a592dddcc5948","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}