RocketChat/Rocket.Chat · error · Meteor.Error
error-invalid-user
error-invalid-user
Error message
Invalid user
What it means
Thrown by the deprecated getTotalChannels Meteor method when the connection has no authenticated user (Meteor.userId() is null). The method only counts public channels (Rooms.countDocuments({ t: 'c' })) but still requires a logged-in caller, and it logs a deprecation warning pointing to /v1/channels.list ahead of removal in 9.0.0.
Source
Thrown at apps/meteor/server/meteor-methods/rooms/getTotalChannels.ts:18
import type { ServerMethods } from '@rocket.chat/ddp-client';
import { Rooms } from '@rocket.chat/models';
import { Meteor } from 'meteor/meteor';
import { methodDeprecationLogger } from '../../lib/deprecationWarningLogger';
declare module '@rocket.chat/ddp-client' {
// eslint-disable-next-line @typescript-eslint/naming-convention
interface ServerMethods {
getTotalChannels(): number;
}
}
Meteor.methods<ServerMethods>({
getTotalChannels() {
methodDeprecationLogger.method('getTotalChannels', '9.0.0', '/v1/channels.list');
if (!Meteor.userId()) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', {
method: 'getTotalChannels',
});
}
return Rooms.countDocuments({ t: 'c' });
},
});
View on GitHub (pinned to b2c16d5842)
Solutions
- Guard with Meteor.userId() and defer the call until login completes
- Re-authenticate if the session token expired
- Replace with GET /api/v1/channels.list (count from the response total) since the method is deprecated
Example fix
// before (deprecated + auth-gated)
const total = await Meteor.callAsync('getTotalChannels');
// after - REST count
const res = await fetch('/api/v1/channels.list?count=0', {
headers: { 'X-Auth-Token': token, 'X-User-Id': uid },
});
const total = (await res.json()).total; Defensive patterns
Strategy: validation
Validate before calling
if (!Meteor.userId()) {
throw new Error('login required');
}
const total = await Meteor.callAsync('getTotalChannels'); Try / catch
try {
const total = await Meteor.callAsync('getTotalChannels');
} catch (e) {
if (e instanceof Meteor.Error && e.error === 'error-invalid-user') {
showLoginScreen();
}
} Prevention
- Migrate to /v1/channels.list - the method is removed in 9.0.0
- Load counts only for authenticated sessions
- Cache the count; it rarely needs live updates
When it happens
Trigger: Meteor.call('getTotalChannels') from an anonymous connection: directory or guest pages that render before login, post-logout reactive recomputation, or an expired resume token.
Common situations: Directory-style UIs loading channel counts on startup; older clients or apps-engine code on the DDP method; sessions cleared by password reset or admin token purge.
Related errors
AI-assisted analysis of RocketChat/Rocket.Chat@b2c16d5842 (2026-08-18).
Data as JSON: /api/errors/83ebbf06b809ae8f.
Report an issue: GitHub.