RocketChat/Rocket.Chat · error · Meteor.Error
error-invalid-user
error-invalid-user
Error message
Invalid user
What it means
Thrown by the 'addUserToRoom' Meteor method (apps/meteor/server/meteor-methods/rooms/addUserToRoom.ts:19) when Meteor.userId() is falsy — the invoking DDP connection has no authenticated user. After the gate it immediately delegates to addUsersToRoomMethod with a single-element users array, so this is purely an authentication failure, not a room/user validation one. The method is deprecated as of 9.0.0 in favor of POST /v1/channels.invite and /v1/groups.invite.
Source
Thrown at apps/meteor/server/meteor-methods/rooms/addUserToRoom.ts:19
import type { ServerMethods } from '@rocket.chat/ddp-client';
import { Meteor } from 'meteor/meteor';
import { addUsersToRoomMethod } from './addUsersToRoom';
import { methodDeprecationLogger } from '../../lib/deprecationWarningLogger';
declare module '@rocket.chat/ddp-client' {
// eslint-disable-next-line @typescript-eslint/naming-convention
interface ServerMethods {
addUserToRoom(data: { rid: string; username: string }): void;
}
}
Meteor.methods<ServerMethods>({
async addUserToRoom(data) {
methodDeprecationLogger.method('addUserToRoom', '9.0.0', ['/v1/channels.invite', '/v1/groups.invite']);
const userId = Meteor.userId();
if (!userId) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', {
method: 'addUserToRoom',
});
}
await addUsersToRoomMethod(userId, {
rid: data.rid,
users: [data.username],
});
},
});
View on GitHub (pinned to b2c16d5842)
Solutions
- Authenticate the connection first and verify with Meteor.userId() before invoking.
- Re-login when the token has expired, then retry.
- Move to the REST invite endpoints (POST /v1/channels.invite, POST /v1/groups.invite) which take explicit auth headers and are the supported path.
- For tests, use a logged-in user fixture connection (e.g. meteor-factory/test login) rather than an anonymous one.
Example fix
// before
Meteor.call('addUserToRoom', { rid, username });
// after
if (!Meteor.userId()) throw new Error('login required');
Meteor.call('addUserToRoom', { rid, username }); Defensive patterns
Strategy: validation
Validate before calling
if (!Meteor.userId()) throw new Error('login required');
Meteor.call('addUserToRoom', { rid, username }); Type guard
const isLoggedIn = (): boolean => Boolean(Meteor.userId());
Try / catch
try {
Meteor.call('addUserToRoom', { rid, username });
} catch (e) {
if (e instanceof Meteor.Error && e.error === 'error-invalid-user') {
// session missing/expired: re-login then retry
}
} Prevention
- Authenticate DDP connections before any method call.
- Migrate to REST invite endpoints (/v1/channels.invite, /v1/groups.invite).
- Gate invite UI on authenticated state.
When it happens
Trigger: Meteor.call('addUserToRoom', { rid, username }) from an unauthenticated or logged-out connection; expired login token; DDP integration that skipped the login handshake; calling the method from server code where no user context is bound.
Common situations: Sessions cleared after password resets or logout on another tab; scripts using DDP without credentials; front-end calling before login finishes; bots connecting with an invalid token that silently leaves userId unset.
Related errors
AI-assisted analysis of RocketChat/Rocket.Chat@b2c16d5842 (2026-08-18).
Data as JSON: /api/errors/18b18e2f32237191.
Report an issue: GitHub.