{"record":{"id":"01a2049e7c7e381b","repo":"Mintplex-Labs/anything-llm","slug":"internal-server-error-01a204","errorCode":null,"errorMessage":"Internal Server Error","messagePattern":"Internal Server Error","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"server/endpoints/api/userManagement/index.js","lineNumber":63,"sourceCode":"      description: \"Instance is not in Multi-User mode. Permission denied.\",\n    }\n      */\n    try {\n      if (!multiUserMode(response))\n        return response\n          .status(401)\n          .send(\"Instance is not in Multi-User mode. Permission denied.\");\n\n      const users = await User.where();\n      const filteredUsers = users.map((user) => ({\n        id: user.id,\n        username: user.username,\n        role: user.role,\n      }));\n      response.status(200).json({ users: filteredUsers });\n    } catch (e) {\n      console.error(e.message, e);\n      response.sendStatus(500).end();\n    }\n  });\n\n  app.get(\n    \"/v1/users/:id/issue-auth-token\",\n    [validApiKey, simpleSSOEnabled],\n    async (request, response) => {\n      /*\n      #swagger.tags = ['User Management']\n      #swagger.description = 'Issue a temporary auth token for a user'\n      #swagger.parameters['id'] = {\n        in: 'path',\n        description: 'The ID of the user to issue a temporary auth token for',\n        required: true,\n        type: 'string'\n      }\n      #swagger.responses[200] = {\n        content: {","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/server/endpoints/api/userManagement/index.js#L45-L81","documentation":"GET /v1/users first gates on multi-user mode (401 otherwise), then runs `User.where()` and maps rows to `{id, username, role}`. The 500 from the catch is therefore a database-layer failure reading the users table — the mapping itself cannot throw for well-formed rows. The actual Prisma error is logged server-side. Note this endpoint requires multi-user mode to be enabled on the instance.","triggerScenarios":"Calling GET /v1/users with a valid API key on a single-user instance that was later converted to multi-user with a broken/partial migration; users table missing after storage reset; DB unreachable at call time.","commonSituations":"Enabling multi-user mode on an old storage volume whose schema predates the users table; database container restarting mid-request; Prisma migration skipped because the server booted against a foreign database.","solutions":["Check server logs for the exact Prisma error (connection vs P2021 table-missing)","Verify multi-user mode is enabled and the instance was restarted after enabling it, so migrations ran","Confirm the database/storage volume belongs to the same AnythingLLM version as the running server","Restore or re-migrate storage; on healthy instances this call is trivial and 200s immediately"],"exampleFix":"// before\nconst {users} = await fetch(`${base}/api/v1/users`, opts).then(r=>r.json());\n\n// after\nconst res = await fetch(`${base}/api/v1/users`, opts);\nif (res.status === 401) throw new Error('instance not in multi-user mode');\nif (res.status === 500) throw new Error('users read failed - check DB migration state');\nconst {users} = await res.json();","handlingStrategy":"try-catch","validationCode":"const probe = await fetch(`${base}/api/v1/users`, opts);\nif (probe.status === 401) throw new Error('enable multi-user mode first');","typeGuard":"const isUserList = (d) => d && Array.isArray(d.users) && d.users.every(u => typeof u.id === 'number' && typeof u.username === 'string');","tryCatchPattern":"try { const {users} = await fetch(usersUrl, opts).then(r=>r.json()); return users; } catch { return []; } // user list is non-critical metadata","preventionTips":["Only call user-management APIs on multi-user instances","Confirm SIMPLE_SSO/multi-user env before building SSO automation","Cache the user list; it changes rarely"],"tags":["anythingllm","user-management","multi-user","prisma","http-500"],"backgroundTag":"database-query-failed","analyzedSha":"3aec848f2885144aa8f1e53b9731a04310d5d558","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}