{"record":{"id":"f8e2026db99d91ab","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-user-f8e202","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/loadSurroundingMessages.ts","lineNumber":35,"sourceCode":"\t\t\tshowThreadMessages?: boolean,\n\t\t):\n\t\t\t| {\n\t\t\t\t\tmessages: IMessage[];\n\t\t\t\t\tmoreBefore: boolean;\n\t\t\t\t\tmoreAfter: boolean;\n\t\t\t  }\n\t\t\t| false;\n\t}\n}\n\nMeteor.methods<ServerMethods>({\n\tasync loadSurroundingMessages(message, limit = 50, showThreadMessages = true) {\n\t\tcheck(message, Object);\n\t\tcheck(limit, Number);\n\t\tcheck(showThreadMessages, Boolean);\n\n\t\tif (!Meteor.userId()) {\n\t\t\tthrow new Meteor.Error('error-invalid-user', 'Invalid user', {\n\t\t\t\tmethod: 'loadSurroundingMessages',\n\t\t\t});\n\t\t}\n\n\t\tconst fromId = Meteor.userId() ?? undefined;\n\n\t\tif (!message._id) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst mainMessage = await Messages.findOneById(message._id);\n\n\t\tif (!mainMessage?.rid) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif (!(await canAccessRoomIdAsync(mainMessage.rid, fromId))) {\n\t\t\treturn false;","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/meteor-methods/messages/loadSurroundingMessages.ts#L17-L53","documentation":"loadSurroundingMessages(message, limit, showThreadMessages) loads context around a given message and requires a logged-in user: Meteor.userId() returning null throws error-invalid-user immediately after the check() argument validation. There is no anonymous path for this method.","triggerScenarios":"Meteor.call('loadSurroundingMessages', message, limit) from a logged-out session, an expired resume token, or an unauthenticated DDP client. Note the argument checks (Object/Number/Boolean) run first, so malformed arguments raise Match errors instead.","commonSituations":"'Jump to message' / context-view actions triggered from stale logged-out tabs; session expiry during long idle periods followed by a click on a message permalink.","solutions":["Gate the surrounding-messages UI on Meteor.userId()","Re-authenticate on session expiry before retrying","Centralize the auth check in a wrapper around history-type methods"],"exampleFix":"// before\nconst result = await Meteor.callAsync('loadSurroundingMessages', message, limit);\n\n// after\nif (!Meteor.userId()) {\n  // require login before loading message context\n} else {\n  const result = await Meteor.callAsync('loadSurroundingMessages', message, limit);\n}","handlingStrategy":"validation","validationCode":"if (!Meteor.userId()) {\n  // message context requires a logged-in user\n}","typeGuard":null,"tryCatchPattern":"try {\n  const result = await Meteor.callAsync('loadSurroundingMessages', message, limit);\n} catch (error) {\n  if (error instanceof Meteor.Error && error.error === 'error-invalid-user') {\n    // re-authenticate before retrying the context load\n  } else {\n    throw error;\n  }\n}","preventionTips":["Gate 'jump to message' actions on login state","Re-check session before firing context loads after long idle periods","Centralize auth checks in a wrapper for history-family methods"],"tags":["authentication","meteor-method","ddp","session"],"backgroundTag":"not-authenticated","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}