{"record":{"id":"da276c4c1e2ad181","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-user-da276c","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/users/setUserStatus.ts","lineNumber":42,"sourceCode":"\t\t});\n\t}\n\n\tconst effectiveStatus = statusType || user.statusDefault || UserStatus.ONLINE;\n\n\tif (effectiveStatus === UserStatus.OFFLINE && !settings.get('Accounts_AllowInvisibleStatusOption')) {\n\t\tthrow new Meteor.Error('error-status-not-allowed', 'Invisible status is disabled', {\n\t\t\tmethod: 'setUserStatus',\n\t\t});\n\t}\n\n\tawait Presence.setStatus(user._id, effectiveStatus, statusText);\n};\n\nMeteor.methods<ServerMethods>({\n\tsetUserStatus: async (statusType, statusText) => {\n\t\tconst user = (await Meteor.userAsync()) as IUser;\n\t\tif (!user) {\n\t\t\tthrow new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'setUserStatus' });\n\t\t}\n\n\t\tawait setUserStatusMethod(user, statusType, statusText);\n\t},\n});\n\nRateLimiter.limitMethod('setUserStatus', 1, 1000, {\n\tuserId: () => true,\n});\n","sourceCodeStart":24,"sourceCodeEnd":52,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/meteor-methods/users/setUserStatus.ts#L24-L52","documentation":"The setUserStatus method wrapper requires an authenticated user: Meteor.userAsync() returned null and the method throws before setUserStatusMethod runs any setting checks.","triggerScenarios":"Meteor.call('setUserStatus', statusType, statusText) executed with no valid session - expired login token, post-logout call, or a server-side invocation without user context.","commonSituations":"Clients auto-setting status on reconnect after the token expired; scripts calling methods before login; tests without a simulated user.","solutions":["Guard with Meteor.userId() before calling and re-authenticate when null","For server-side flows use a REST endpoint with a token instead of the DDP method","Catch error-invalid-user and route back to login"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const uid = Meteor.userId();\nif (!uid) {\n  throw new Error('Login required before setting status');\n}","typeGuard":null,"tryCatchPattern":"catch (err) {\n  if (err instanceof Meteor.Error && err.error === 'error-invalid-user') {\n    reauthenticate(); // then re-apply the status once\n  }\n}","preventionTips":["Do not auto-fire status updates on reconnect until Meteor.userId() is confirmed","Queue the intended status and apply it after a successful re-login instead of retrying blindly","Centralize invalid-user handling for all account methods"],"tags":["meteor","presence","authentication","ddp"],"backgroundTag":"authentication-required","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","contentChangedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}