{"record":{"id":"278c34ec0b194161","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-user-278c34","errorCode":"error-invalid-user","errorMessage":"Invalid user","messagePattern":"Invalid user","errorType":"error_code","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/publications/messages.ts","lineNumber":296,"sourceCode":"\n\tif (!type) {\n\t\tthrow new Meteor.Error('error-param-required', 'The \"type\" or \"lastUpdate\" parameters must be provided');\n\t}\n\n\treturn handleCursorPagination(type, rid, count, next, previous);\n};\n\nMeteor.methods<ServerMethods>({\n\tasync 'messages/get'(\n\t\trid,\n\t\t{ lastUpdate, latestDate = new Date(), oldestDate, inclusive = false, count = 20, unreads = false, next, previous, type },\n\t) {\n\t\tcheck(rid, String);\n\n\t\tconst fromId = Meteor.userId();\n\n\t\tif (!fromId) {\n\t\t\tthrow new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'messages/get' });\n\t\t}\n\n\t\tif (!rid) {\n\t\t\tthrow new Meteor.Error('error-invalid-room', 'Invalid room', { method: 'messages/get' });\n\t\t}\n\n\t\treturn getMessageHistory(rid, fromId, { lastUpdate, latestDate, oldestDate, inclusive, count, unreads, next, previous, type });\n\t},\n});\n","sourceCodeStart":278,"sourceCodeEnd":306,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/publications/messages.ts#L278-L306","documentation":"Thrown by the 'messages/get' Meteor method when Meteor.userId() returns null, i.e. the DDP connection that invoked the method is not authenticated. Meteor methods rely on the connection's login token; without one there is no user context to authorize room access. The error includes { method: 'messages/get' } in its details.","triggerScenarios":"Calling Meteor.call('messages/get', ...) before Meteor.loginWithPassword/Token completes; calling after the session token expired and was purged; invoking the method from a server-side context with no authenticated connection.","commonSituations":"Client boot races where history loads before login finishes; resumed sessions with revoked tokens; test harnesses that call methods on a bare DDP connection.","solutions":["Ensure login resolved before requesting history (await the login promise or react to Account.onLogin)","Re-authenticate when the token expired and retry the call","For server-side scripts, use an authenticated DDP client or call the underlying service with an explicit userId"],"exampleFix":"// before\nMeteor.call('messages/get', rid, {});\n\n// after\nawait promiseMeteorCall('login', { resume: token });\nMeteor.call('messages/get', rid, {});","handlingStrategy":"validation","validationCode":"if (!Meteor.userId()) {\n  throw new Error('login required before messages/get');\n}\nMeteor.call('messages/get', rid, params);","typeGuard":null,"tryCatchPattern":"try { await Meteor.callAsync('messages/get', rid, params); } catch (e) { if (e.error === 'error-invalid-user') { /* re-authenticate, then retry once */ } }","preventionTips":["Gate history loads on Account.onLogin / a non-null Meteor.userId()","Handle token expiration globally (401-like handling for DDP) instead of per call"],"tags":["meteor","authentication","messages-get","rocket-chat"],"backgroundTag":"authentication-required","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T10:36:37.832Z"}