{"record":{"id":"a523ff9aa8d3516e","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-user-a523ff","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/messages/getChannelHistory.ts","lineNumber":163,"sourceCode":"\t\treturn {\n\t\t\tmessages: messages || [],\n\t\t\tfirstUnread,\n\t\t\tunreadNotLoaded,\n\t\t};\n\t}\n\n\treturn {\n\t\tmessages: messages || [],\n\t};\n};\n\nMeteor.methods<ServerMethods>({\n\tasync getChannelHistory({ rid, latest, oldest, inclusive, offset = 0, count = 20, unreads, showThreadMessages = true }) {\n\t\tmethodDeprecationLogger.method('getChannelHistory', '9.0.0', '/v1/channels.history');\n\t\tcheck(rid, String);\n\n\t\tif (!Meteor.userId()) {\n\t\t\tthrow new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'getChannelHistory' });\n\t\t}\n\n\t\tconst fromUserId = Meteor.userId();\n\t\tif (!fromUserId) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn getChannelHistory({ rid, fromUserId, latest, oldest, inclusive, offset, count, unreads, showThreadMessages });\n\t},\n});\n","sourceCodeStart":145,"sourceCodeEnd":174,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/meteor-methods/messages/getChannelHistory.ts#L145-L174","documentation":"The getChannelHistory Meteor-method wrapper throws 'error-invalid-user' when Meteor.userId() is null — channel history requires an authenticated caller because room-read authorization (Authorization.canReadRoom) is evaluated per user. The method is deprecated since 9.0.0 in favor of GET /v1/channels.history.","triggerScenarios":"Meteor.call('getChannelHistory', { rid, latest, oldest, ... }) from an expired, revoked, or anonymous DDP session.","commonSituations":"Infinite-scroll / history loaders firing after token expiry; integrations fetching history over DDP without login; long-lived dashboards that outlive their session.","solutions":["Check Meteor.userId() first; re-authenticate when null","Switch to GET /v1/channels.history with an auth token (deprecation target)","Make history loaders retry once after a re-login instead of failing the panel"],"exampleFix":"// before\nMeteor.call('getChannelHistory', { rid });\n\n// after\nif (!Meteor.userId()) {\n  // re-login before loading history\n}\nMeteor.call('getChannelHistory', { rid });","handlingStrategy":"validation","validationCode":"if (!Meteor.userId()) {\n  // re-login before loading history\n} else {\n  Meteor.call('getChannelHistory', { rid, latest, oldest, inclusive, offset, count });\n}","typeGuard":null,"tryCatchPattern":"try {\n  const history = await Meteor.callAsync('getChannelHistory', params);\n} catch (e) {\n  if ((e as Meteor.Error).error === 'error-invalid-user') {\n    // session expired mid-scroll: re-auth and reload the history panel\n  }\n}","preventionTips":["Check Meteor.userId() in loaders that run automatically (infinite scroll)","Migrate to GET /v1/channels.history with a token (deprecation target)","Retry history loads once after re-login instead of leaving the panel empty"],"tags":["meteor","ddp","authentication","history"],"backgroundTag":"user-not-authenticated","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}