{"record":{"id":"e2866b82a646af0a","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-user-e2866b","errorCode":"error-invalid-user","errorMessage":"Invalid user","messagePattern":"Invalid user","errorType":"error_code","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/meteor-methods/rooms/channelsList.ts","lineNumber":33,"sourceCode":"declare module '@rocket.chat/ddp-client' {\n\t// eslint-disable-next-line @typescript-eslint/naming-convention\n\tinterface ServerMethods {\n\t\tchannelsList(filter: string, channelType: string, limit?: number, sort?: string): { channels: IRoom[] };\n\t}\n}\n\nMeteor.methods<ServerMethods>({\n\tasync channelsList(filter, channelType, limit, sort) {\n\t\tmethodDeprecationLogger.method('channelsList', '9.0.0', '/v1/channels.list');\n\t\tcheck(filter, String);\n\t\tcheck(channelType, String);\n\t\tcheck(limit, Match.Optional(Number));\n\t\tcheck(sort, Match.Optional(String));\n\n\t\tconst userId = Meteor.userId();\n\n\t\tif (!userId) {\n\t\t\tthrow new Meteor.Error('error-invalid-user', 'Invalid user', {\n\t\t\t\tmethod: 'channelsList',\n\t\t\t});\n\t\t}\n\n\t\tconst options: FindOptions<IRoom> = {\n\t\t\tprojection: {\n\t\t\t\tname: 1,\n\t\t\t\tt: 1,\n\t\t\t},\n\t\t\tsort: {\n\t\t\t\tmsgs: -1,\n\t\t\t},\n\t\t};\n\n\t\tif (_.isNumber(limit)) {\n\t\t\toptions.limit = limit;\n\t\t}\n","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/meteor-methods/rooms/channelsList.ts#L15-L51","documentation":"Authentication gate of the channelsList Meteor method (deprecated in 9.0.0 in favor of GET /v1/channels.list): Meteor.userId() was null when the method executed. Even though the method only lists channels, it requires a logged-in user because its results are permission-filtered (e.g. view-p-room for the private-channel branch).","triggerScenarios":"Calling Meteor.call('channelsList', filter, channelType, limit, sort) before the client's login completed; invoking after the login token expired or was invalidated; a DDP script that connects but never logs in.","commonSituations":"Directory/search UI loading during boot racing the Accounts login; sessions invalidated by password change or server restart; automated clients forgetting the login step.","solutions":["Await a successful login before calling channelsList (react on Meteor.userId() becoming non-null).","Re-authenticate if the session was invalidated, then retry.","Use GET /api/v1/channels.list with token auth for server-side integrations."],"exampleFix":"// before\nMeteor.call('channelsList', filter, channelType);\n\n// after\nif (Meteor.userId()) {\n  Meteor.call('channelsList', filter, channelType);\n} else {\n  await relogin();\n  Meteor.call('channelsList', filter, channelType);\n}","handlingStrategy":"validation","validationCode":"if (!Meteor.userId()) {\n  // channelsList requires a logged-in user - redirect to login instead of calling\n}","typeGuard":null,"tryCatchPattern":"try {\n  const result = await Meteor.callAsync('channelsList', filter, channelType, limit, sort);\n} catch (e) {\n  if (e instanceof Meteor.Error && e.error === 'error-invalid-user') {\n    // session gone: re-login, then retry the listing once\n    await relogin();\n    return Meteor.callAsync('channelsList', filter, channelType, limit, sort);\n  }\n  throw e;\n}","preventionTips":["Do not call channelsList during boot before the login state resolves.","Cache listing data across brief reconnects instead of calling with an anonymous connection.","Prefer GET /api/v1/channels.list for server-side integrations."],"tags":["rocket-chat","meteor","ddp","channels-list","authentication"],"backgroundTag":"meteor-invalid-user","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}