{"record":{"id":"cef8eb6b31c3cbc4","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-user-cef8eb","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/cleanRoomHistory.ts","lineNumber":94,"sourceCode":"\t\tignoreDiscussion = true,\n\t\tfilesOnly = false,\n\t\tfromUsers = [],\n\t\tignoreThreads,\n\t}) {\n\t\tcheck(roomId, String);\n\t\tcheck(latest, Date);\n\t\tcheck(oldest, Date);\n\t\tcheck(inclusive, Boolean);\n\t\tcheck(limit, Match.Maybe(Number));\n\t\tcheck(excludePinned, Match.Maybe(Boolean));\n\t\tcheck(filesOnly, Match.Maybe(Boolean));\n\t\tcheck(ignoreThreads, Match.Maybe(Boolean));\n\t\tcheck(fromUsers, Match.Maybe([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', { method: 'cleanRoomHistory' });\n\t\t}\n\n\t\treturn cleanRoomHistoryMethod(userId, {\n\t\t\troomId,\n\t\t\tlatest,\n\t\t\toldest,\n\t\t\tinclusive,\n\t\t\tlimit,\n\t\t\texcludePinned,\n\t\t\tignoreDiscussion,\n\t\t\tfilesOnly,\n\t\t\tfromUsers,\n\t\t\tignoreThreads,\n\t\t});\n\t},\n});\n","sourceCodeStart":76,"sourceCodeEnd":111,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/meteor-methods/rooms/cleanRoomHistory.ts#L76-L111","documentation":"Authentication gate of the cleanRoomHistory Meteor method wrapper: after the check() validations of latest/oldest/inclusive/limit/excludePinned/filesOnly/ignoreThreads/fromUsers, Meteor.userId() returned null. The method requires an authenticated DDP connection because history cleaning is a permissioned, destructive action.","triggerScenarios":"Calling Meteor.call('cleanRoomHistory', ...) on a connection without login or with an expired token; server-side invocation outside a user context.","commonSituations":"Prune tooling loaded before login completes; sessions invalidated by restarts or password changes; scripts skipping the DDP login step.","solutions":["Ensure Meteor.userId() is set before calling; await login on the client.","Re-authenticate when the session has expired.","Use the REST cleaning endpoint (POST /api/v1/rooms.cleanHistory) with token auth for scheduled jobs."],"exampleFix":"// before\nMeteor.call('cleanRoomHistory', roomId, latest, oldest);\n\n// after\nif (!Meteor.userId()) {\n  await relogin();\n}\nMeteor.call('cleanRoomHistory', roomId, latest, oldest);","handlingStrategy":"validation","validationCode":"if (!Meteor.userId()) {\n  // cleanRoomHistory needs an authenticated connection - log in first\n}","typeGuard":null,"tryCatchPattern":"try {\n  await Meteor.callAsync('cleanRoomHistory', roomId, latest, oldest);\n} catch (e) {\n  if (e instanceof Meteor.Error && e.error === 'error-invalid-user') {\n    await relogin(); // then let the user retry once\n    return;\n  }\n  throw e;\n}","preventionTips":["Gate destructive admin tooling behind a logged-in, permissioned session.","Use REST rooms.cleanHistory with token auth for scheduled pruning jobs.","Send Date objects (not strings) for latest/oldest so the check() validations pass first."],"tags":["rocket-chat","meteor","ddp","clean-history","authentication"],"backgroundTag":"meteor-invalid-user","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}