{"record":{"id":"2ec6c51e8daf484b","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-user-2ec6c5","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/getRoomIdByNameOrId.ts","lineNumber":23,"sourceCode":"import { Meteor } from 'meteor/meteor';\n\nimport { canAccessRoomAsync } from '../../lib/authorization';\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\tgetRoomIdByNameOrId(rid: string): string;\n\t}\n}\n\nMeteor.methods<ServerMethods>({\n\tasync getRoomIdByNameOrId(rid) {\n\t\tmethodDeprecationLogger.method('getRoomIdByNameOrId', '9.0.0', '/v1/rooms.info');\n\t\tcheck(rid, String);\n\n\t\tif (!Meteor.userId()) {\n\t\t\tthrow new Meteor.Error('error-invalid-user', 'Invalid user', {\n\t\t\t\tmethod: 'getRoomIdByNameOrId',\n\t\t\t});\n\t\t}\n\n\t\tconst room = (await Rooms.findOneById(rid)) || (await Rooms.findOneByName(rid));\n\n\t\tif (room == null) {\n\t\t\tthrow new Meteor.Error('error-not-allowed', 'Not allowed', {\n\t\t\t\tmethod: 'getRoomIdByNameOrId',\n\t\t\t});\n\t\t}\n\n\t\tif (!(await canAccessRoomAsync(room, (await Meteor.userAsync()) ?? undefined))) {\n\t\t\tthrow new Meteor.Error('error-not-allowed', 'Not allowed', {\n\t\t\t\tmethod: 'getRoomIdByNameOrId',\n\t\t\t});\n\t\t}\n","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/meteor-methods/rooms/getRoomIdByNameOrId.ts#L5-L41","documentation":"Thrown by the deprecated getRoomIdByNameOrId Meteor method when the connection has no authenticated user (Meteor.userId() is null). The method also logs a deprecation warning (removal targeted for 9.0.0, replacement /v1/rooms.info), so anonymous calls fail immediately after the deprecation logger runs.","triggerScenarios":"Meteor.call('getRoomIdByNameOrId', rid) invoked before login completes, after logout, or with an expired resume token; also any code path that runs on page load before the Accounts session is restored.","commonSituations":"Migrating old clients or apps-engine code that still resolves room ids via DDP; startup code calling the method before Meteor.userId() is set; session lost after a server restart rotated token secrets.","solutions":["Ensure the user is logged in before calling (guard on Meteor.userId())","Re-login to establish a fresh resume token if the session expired","Replace the call with GET /api/v1/rooms.info (roomId or roomName param) since the method is deprecated for 9.0.0"],"exampleFix":"// before (deprecated + fails when logged out)\nconst id = await Meteor.callAsync('getRoomIdByNameOrId', nameOrId);\n\n// after - use the REST endpoint with an auth header\nconst res = await fetch('/api/v1/rooms.info?roomName=' + encodeURIComponent(nameOrId), {\n  headers: { 'X-Auth-Token': token, 'X-User-Id': uid },\n});\nconst id = (await res.json()).room?._id;","handlingStrategy":"validation","validationCode":"if (!Meteor.userId()) {\n  throw new Error('login required');\n}\nconst id = await Meteor.callAsync('getRoomIdByNameOrId', rid);","typeGuard":null,"tryCatchPattern":"try {\n  const id = await Meteor.callAsync('getRoomIdByNameOrId', rid);\n} catch (e) {\n  if (e instanceof Meteor.Error && e.error === 'error-invalid-user') {\n    await reauthenticate();\n  }\n}","preventionTips":["Migrate off this method - it is removed in 9.0.0 in favor of /v1/rooms.info","Resolve room ids only after the Accounts session is established","Cache resolved name->id mappings to avoid repeated 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"}