RocketChat/Rocket.Chat · error · Meteor.Error
error-invalid-user
error-invalid-user
Error message
Invalid user
What it means
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.
Source
Thrown at apps/meteor/server/meteor-methods/rooms/getRoomIdByNameOrId.ts:23
import { Meteor } from 'meteor/meteor';
import { canAccessRoomAsync } from '../../lib/authorization';
import { methodDeprecationLogger } from '../../lib/deprecationWarningLogger';
declare module '@rocket.chat/ddp-client' {
// eslint-disable-next-line @typescript-eslint/naming-convention
interface ServerMethods {
getRoomIdByNameOrId(rid: string): string;
}
}
Meteor.methods<ServerMethods>({
async getRoomIdByNameOrId(rid) {
methodDeprecationLogger.method('getRoomIdByNameOrId', '9.0.0', '/v1/rooms.info');
check(rid, String);
if (!Meteor.userId()) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', {
method: 'getRoomIdByNameOrId',
});
}
const room = (await Rooms.findOneById(rid)) || (await Rooms.findOneByName(rid));
if (room == null) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', {
method: 'getRoomIdByNameOrId',
});
}
if (!(await canAccessRoomAsync(room, (await Meteor.userAsync()) ?? undefined))) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', {
method: 'getRoomIdByNameOrId',
});
}
View on GitHub (pinned to b2c16d5842)
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
Example fix
// before (deprecated + fails when logged out)
const id = await Meteor.callAsync('getRoomIdByNameOrId', nameOrId);
// after - use the REST endpoint with an auth header
const res = await fetch('/api/v1/rooms.info?roomName=' + encodeURIComponent(nameOrId), {
headers: { 'X-Auth-Token': token, 'X-User-Id': uid },
});
const id = (await res.json()).room?._id; Defensive patterns
Strategy: validation
Validate before calling
if (!Meteor.userId()) {
throw new Error('login required');
}
const id = await Meteor.callAsync('getRoomIdByNameOrId', rid); Try / catch
try {
const id = await Meteor.callAsync('getRoomIdByNameOrId', rid);
} catch (e) {
if (e instanceof Meteor.Error && e.error === 'error-invalid-user') {
await reauthenticate();
}
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
AI-assisted analysis of RocketChat/Rocket.Chat@b2c16d5842 (2026-08-18).
Data as JSON: /api/errors/2ec6c51e8daf484b.
Report an issue: GitHub.