{"record":{"id":"f6c5363725814a0f","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-user-f6c536","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/rooms/getRoomNameById.ts","lineNumber":23,"sourceCode":"import { Meteor } from 'meteor/meteor';\n\nimport { hasPermissionAsync } from '../../lib/authorization/hasPermission';\nimport { methodDeprecationLogger } from '../../lib/deprecationWarningLogger';\n\ndeclare module '@rocket.chat/ddp-client' {\n\t// eslint-disable-next-line @typescript-eslint/naming-convention\n\tinterface ServerMethods {\n\t\tgetRoomNameById(rid: IRoom['_id']): Promise<string | undefined>;\n\t}\n}\n\nMeteor.methods<ServerMethods>({\n\tasync getRoomNameById(rid) {\n\t\tmethodDeprecationLogger.method('getRoomNameById', '9.0.0', '/v1/rooms.info');\n\t\tcheck(rid, String);\n\t\tconst userId = Meteor.userId();\n\t\tif (!userId) {\n\t\t\tthrow new Meteor.Error('error-invalid-user', 'Invalid user', {\n\t\t\t\tmethod: 'getRoomNameById',\n\t\t\t});\n\t\t}\n\n\t\tconst room = await Rooms.findOneById(rid);\n\n\t\tif (room == null) {\n\t\t\tthrow new Meteor.Error('error-not-allowed', 'Not allowed', {\n\t\t\t\tmethod: 'getRoomNameById',\n\t\t\t});\n\t\t}\n\n\t\tconst subscription = await Subscriptions.findOneByRoomIdAndUserId(rid, userId, {\n\t\t\tprojection: { _id: 1 },\n\t\t});\n\t\tif (subscription) {\n\t\t\treturn room.name;\n\t\t}","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/meteor-methods/rooms/getRoomNameById.ts#L5-L41","documentation":"Thrown by the deprecated getRoomNameById Meteor method when the connection has no authenticated user (Meteor.userId() is null). The method is slated for removal in 9.0.0 in favor of /v1/rooms.info, and every call first logs a deprecation warning before the auth guard rejects anonymous connections.","triggerScenarios":"Meteor.call('getRoomNameById', rid) executed pre-login, post-logout, or with an expired resume token; legacy client code resolving display names for room ids during startup before the session is restored.","commonSituations":"Older clients or apps-engine packages still on the DDP method; notifications/webhook rendering code that runs without a user context; token invalidation after user password reset or admin session purge.","solutions":["Ensure login is complete before calling (guard on Meteor.userId())","Re-authenticate to get a fresh resume token","Replace with GET /api/v1/rooms.info?roomId=... and read room.name from the response"],"exampleFix":"// before (deprecated, fails when anonymous)\nconst name = await Meteor.callAsync('getRoomNameById', rid);\n\n// after - REST with auth headers\nconst res = await fetch('/api/v1/rooms.info?roomId=' + encodeURIComponent(rid), {\n  headers: { 'X-Auth-Token': token, 'X-User-Id': uid },\n});\nconst name = (await res.json()).room?.name;","handlingStrategy":"validation","validationCode":"if (!Meteor.userId()) {\n  throw new Error('login required');\n}\nconst name = await Meteor.callAsync('getRoomNameById', rid);","typeGuard":"// returns Promise<string | undefined>\nconst isRoomName = (v: string | undefined): v is string => typeof v === 'string';\nconst name = await Meteor.callAsync('getRoomNameById', rid);\nif (isRoomName(name)) render(name);","tryCatchPattern":"try {\n  const name = await Meteor.callAsync('getRoomNameById', rid);\n} catch (e) {\n  if (e instanceof Meteor.Error && e.error === 'error-invalid-user') {\n    showLoginScreen();\n  }\n}","preventionTips":["Migrate to /v1/rooms.info - the method is removed in 9.0.0","Resolve names lazily and only for rooms already in the user's context","Cache name results to avoid repeated permission-gated lookups"],"tags":["meteor","ddp","authentication","rooms","deprecated"],"backgroundTag":"unauthenticated-request","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}