RocketChat/Rocket.Chat · error · Meteor.Error

error-invalid-user

error-invalid-user

Error message

Invalid user

What it means

Thrown by the 'getStatistics' Meteor method when there is no authenticated user. The method returns workspace statistics via getLastStatistics({ userId: uid, refresh }) and resolves the caller from Meteor.userId(); a null uid aborts before statistics are gathered. Deprecated since 9.0.0 in favor of /v1/statistics (named by its deprecation logger).

Source

Thrown at apps/meteor/server/meteor-methods/platform/getStatistics.ts:20

import type { ServerMethods } from '@rocket.chat/ddp-client';
import { Meteor } from 'meteor/meteor';

import { methodDeprecationLogger } from '../../lib/deprecationWarningLogger';
import { getLastStatistics } from '../../lib/statistics/functions/getLastStatistics';

declare module '@rocket.chat/ddp-client' {
	// eslint-disable-next-line @typescript-eslint/naming-convention
	interface ServerMethods {
		getStatistics(refresh?: boolean): IStats;
	}
}

Meteor.methods<ServerMethods>({
	async getStatistics(refresh) {
		methodDeprecationLogger.method('getStatistics', '9.0.0', '/v1/statistics');
		const uid = Meteor.userId();
		if (!uid) {
			throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'getStatistics' });
		}
		return getLastStatistics({
			userId: uid,
			refresh,
		});
	},
});

View on GitHub (pinned to b2c16d5842)

Solutions

  1. Re-authenticate and retry the statistics fetch
  2. Guard with Meteor.userId() before calling
  3. Migrate to GET /v1/statistics with an authenticated request (deprecation already logged)
  4. Silence the fetch entirely when no session is present

Example fix

// before
const stats = await Meteor.callAsync('getStatistics', refresh);

// after
if (!Meteor.userId()) {
  return handleSessionExpired();
}
const stats = await Meteor.callAsync('getStatistics', refresh);
// 9.x+: prefer GET /v1/statistics with an authenticated request
Defensive patterns

Strategy: validation

Validate before calling

// client: statistics fetch requires a session
if (!Meteor.userId()) {
  // skip or defer the statistics fetch
}

Type guard

import { Meteor } from 'meteor/meteor';

const isMeteorError = (err: unknown, code?: string): err is Meteor.Error =>
  err instanceof Meteor.Error && (code === undefined || err.error === code);

Try / catch

try {
  const stats = await Meteor.callAsync('getStatistics', refresh);
} catch (err) {
  if (isMeteorError(err, 'error-invalid-user')) {
    // session expired: re-authenticate and refetch
  } else {
    throw err;
  }
}

Prevention

When it happens

Trigger: The statistics/instance info panel loads with an expired session; monitoring scripts call the DDP method without login; a logged-out admin view still triggers the fetch.

Common situations: Admin dashboards polled after token expiry; automated monitoring not authenticated; 9.x migrations to GET /v1/statistics.

Related errors


AI-assisted analysis of RocketChat/Rocket.Chat@b2c16d5842 (2026-08-18). Data as JSON: /api/errors/78771ad3774821f3. Report an issue: GitHub.