{"record":{"id":"1f6817dcbc347720","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-user-1f6817","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/unfollowMessage.ts","lineNumber":59,"sourceCode":"\n\tvoid notifyOnMessageChange({\n\t\tid,\n\t});\n\n\tconst isFollowed = false;\n\tawait Apps.self?.triggerEvent(AppEvents.IPostMessageFollowed, message, user, isFollowed);\n\n\treturn unfollowResult;\n};\n\nMeteor.methods<ServerMethods>({\n\tasync unfollowMessage({ mid }) {\n\t\tmethodDeprecationLogger.method('unfollowMessage', '9.0.0', '/v1/chat.unfollowMessage');\n\t\tcheck(mid, String);\n\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: 'unfollowMessage' });\n\t\t}\n\n\t\treturn unfollowMessage(user, { mid });\n\t},\n});\n\nRateLimiter.limitMethod('unfollowMessage', 5, 5000, {\n\tuserId() {\n\t\treturn true;\n\t},\n});\n","sourceCodeStart":41,"sourceCodeEnd":71,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/meteor-methods/messages/unfollowMessage.ts#L41-L71","documentation":"The Meteor method wrapper for unfollowMessage requires an authenticated connection: it loads the user with Meteor.userAsync() and throws error-invalid-user when null. The check runs after check(mid, String), so a non-string mid fails earlier with a Match error instead.","triggerScenarios":"Calling unfollowMessage before login completes; expired resume token after server restart or logout; script/DDL client without a login handshake.","commonSituations":"Race between page load and login for thread follow actions; long-lived connections that silently became anonymous.","solutions":["Ensure the session is authenticated before calling unfollowMessage","Re-login and retry once on reconnect","Gate thread follow UI on the logged-in state"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// client: require an authenticated session and a string mid\nif (!Meteor.userId() || typeof mid !== 'string') {\n\treturn;\n}\nawait Meteor.callAsync('unfollowMessage', { mid });","typeGuard":null,"tryCatchPattern":"try {\n\tawait Meteor.callAsync('unfollowMessage', { mid });\n} catch (e: any) {\n\tif (e?.error === 'error-invalid-user' && !Meteor.userId()) {\n\t\t// re-login and retry once\n\t}\n\tthrow e;\n}","preventionTips":["Gate follow actions on the logged-in state","Pass mid as a string; other types fail the check(mid, String) guard earlier","Handle re-authentication centrally for all deprecated thread methods"],"tags":["meteor-method","authentication","threads","deprecated"],"backgroundTag":"authentication-required","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}