{"record":{"id":"80022cbe666c3bf9","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-user-80022c","errorCode":"error-invalid-user","errorMessage":"Invalid user","messagePattern":"Invalid user","errorType":"error_code","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/lib/messaging/stars/starMessage.ts","lineNumber":70,"sourceCode":"\n\tawait Apps.self?.triggerEvent(AppEvents.IPostMessageStarred, message, user, message.starred);\n\n\tawait Messages.updateUserStarById(message._id, user._id, message.starred);\n\n\tvoid notifyOnMessageChange({\n\t\tid: message._id,\n\t});\n\n\treturn true;\n};\n\nMeteor.methods<ServerMethods>({\n\tasync starMessage(message) {\n\t\tmethodDeprecationLogger.method('starMessage', '9.0.0', '/v1/chat.starMessage');\n\t\tconst user = (await Meteor.userAsync()) as IUser;\n\n\t\tif (!user) {\n\t\t\tthrow new Meteor.Error('error-invalid-user', 'Invalid user', {\n\t\t\t\tmethod: 'starMessage',\n\t\t\t});\n\t\t}\n\n\t\treturn starMessage(user, message);\n\t},\n});\n","sourceCodeStart":52,"sourceCodeEnd":78,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/lib/messaging/stars/starMessage.ts#L52-L78","documentation":"The Meteor method wrapper for starMessage resolves the caller with Meteor.userAsync(); when that returns null (no authenticated user on the connection) it throws Meteor.Error('error-invalid-user', 'Invalid user'). It is purely an authentication gate: the DDP method was invoked on a connection without a logged-in user.","triggerScenarios":"Calling Meteor.call('starMessage', msg) before login finishes, after logout/session expiry (token invalid), or from a server-side connection that has no bound this.userId.","commonSituations":"Page reloaded and the star clicked before the login resumed; token expired mid-session; logged out in another tab; automated scripts forgetting to authenticate.","solutions":["Ensure Meteor.userId() is set before invoking starMessage","Queue the action and re-run it after the login-resume completes","In automated clients, establish credentials and wait for authentication before calling user-scoped methods"],"exampleFix":"// before\nMeteor.call('starMessage', msg); // called while logged out\n\n// after\nTracker.autorun((c) => {\n  if (Meteor.userId()) {\n    Meteor.call('starMessage', msg);\n    c.stop();\n  }\n});","handlingStrategy":"validation","validationCode":"if (!Meteor.userId()) {\n  await reauthenticate();\n}\nif (Meteor.userId()) {\n  Meteor.call('starMessage', msg);\n}","typeGuard":"const isAuthenticated = (): boolean => typeof Meteor.userId() === 'string';","tryCatchPattern":"Meteor.call('starMessage', msg, (err) => {\n  if (err?.error === 'error-invalid-user') {\n    routeToLogin({ back: currentRoute }); // session is gone - stop and re-login\n  }\n});","preventionTips":["Gate all user-scoped method calls behind a Meteor.userId() check","Queue UI actions and replay them after login-resume instead of firing blind","Treat error-invalid-user from method wrappers as an auth-expiry signal"],"tags":["starring","authentication","ddp-method"],"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"}