{"record":{"id":"83ebbf06b809ae8f","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-user-83ebbf","errorCode":"error-invalid-user","errorMessage":"Invalid user","messagePattern":"Invalid user","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/meteor-methods/rooms/getTotalChannels.ts","lineNumber":18,"sourceCode":"import type { ServerMethods } from '@rocket.chat/ddp-client';\nimport { Rooms } from '@rocket.chat/models';\nimport { Meteor } from 'meteor/meteor';\n\nimport { methodDeprecationLogger } from '../../lib/deprecationWarningLogger';\n\ndeclare module '@rocket.chat/ddp-client' {\n\t// eslint-disable-next-line @typescript-eslint/naming-convention\n\tinterface ServerMethods {\n\t\tgetTotalChannels(): number;\n\t}\n}\n\nMeteor.methods<ServerMethods>({\n\tgetTotalChannels() {\n\t\tmethodDeprecationLogger.method('getTotalChannels', '9.0.0', '/v1/channels.list');\n\t\tif (!Meteor.userId()) {\n\t\t\tthrow new Meteor.Error('error-invalid-user', 'Invalid user', {\n\t\t\t\tmethod: 'getTotalChannels',\n\t\t\t});\n\t\t}\n\n\t\treturn Rooms.countDocuments({ t: 'c' });\n\t},\n});\n","sourceCodeStart":1,"sourceCodeEnd":26,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/meteor-methods/rooms/getTotalChannels.ts#L1-L26","documentation":"Thrown by the deprecated getTotalChannels Meteor method when the connection has no authenticated user (Meteor.userId() is null). The method only counts public channels (Rooms.countDocuments({ t: 'c' })) but still requires a logged-in caller, and it logs a deprecation warning pointing to /v1/channels.list ahead of removal in 9.0.0.","triggerScenarios":"Meteor.call('getTotalChannels') from an anonymous connection: directory or guest pages that render before login, post-logout reactive recomputation, or an expired resume token.","commonSituations":"Directory-style UIs loading channel counts on startup; older clients or apps-engine code on the DDP method; sessions cleared by password reset or admin token purge.","solutions":["Guard with Meteor.userId() and defer the call until login completes","Re-authenticate if the session token expired","Replace with GET /api/v1/channels.list (count from the response total) since the method is deprecated"],"exampleFix":"// before (deprecated + auth-gated)\nconst total = await Meteor.callAsync('getTotalChannels');\n\n// after - REST count\nconst res = await fetch('/api/v1/channels.list?count=0', {\n  headers: { 'X-Auth-Token': token, 'X-User-Id': uid },\n});\nconst total = (await res.json()).total;","handlingStrategy":"validation","validationCode":"if (!Meteor.userId()) {\n  throw new Error('login required');\n}\nconst total = await Meteor.callAsync('getTotalChannels');","typeGuard":null,"tryCatchPattern":"try {\n  const total = await Meteor.callAsync('getTotalChannels');\n} catch (e) {\n  if (e instanceof Meteor.Error && e.error === 'error-invalid-user') {\n    showLoginScreen();\n  }\n}","preventionTips":["Migrate to /v1/channels.list - the method is removed in 9.0.0","Load counts only for authenticated sessions","Cache the count; it rarely needs live updates"],"tags":["meteor","ddp","authentication","rooms","deprecated"],"backgroundTag":"unauthenticated-request","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}