RocketChat/Rocket.Chat · error · Meteor.Error

error-invalid-user

error-invalid-user

Error message

Invalid user

What it means

The setUserStatus method wrapper requires an authenticated user: Meteor.userAsync() returned null and the method throws before setUserStatusMethod runs any setting checks.

Source

Thrown at apps/meteor/server/meteor-methods/users/setUserStatus.ts:42

		});
	}

	const effectiveStatus = statusType || user.statusDefault || UserStatus.ONLINE;

	if (effectiveStatus === UserStatus.OFFLINE && !settings.get('Accounts_AllowInvisibleStatusOption')) {
		throw new Meteor.Error('error-status-not-allowed', 'Invisible status is disabled', {
			method: 'setUserStatus',
		});
	}

	await Presence.setStatus(user._id, effectiveStatus, statusText);
};

Meteor.methods<ServerMethods>({
	setUserStatus: async (statusType, statusText) => {
		const user = (await Meteor.userAsync()) as IUser;
		if (!user) {
			throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'setUserStatus' });
		}

		await setUserStatusMethod(user, statusType, statusText);
	},
});

RateLimiter.limitMethod('setUserStatus', 1, 1000, {
	userId: () => true,
});

View on GitHub (pinned to b2c16d5842)

Solutions

  1. Guard with Meteor.userId() before calling and re-authenticate when null
  2. For server-side flows use a REST endpoint with a token instead of the DDP method
  3. Catch error-invalid-user and route back to login
Defensive patterns

Strategy: validation

Validate before calling

const uid = Meteor.userId();
if (!uid) {
  throw new Error('Login required before setting status');
}

Try / catch

catch (err) {
  if (err instanceof Meteor.Error && err.error === 'error-invalid-user') {
    reauthenticate(); // then re-apply the status once
  }
}

Prevention

When it happens

Trigger: Meteor.call('setUserStatus', statusType, statusText) executed with no valid session - expired login token, post-logout call, or a server-side invocation without user context.

Common situations: Clients auto-setting status on reconnect after the token expired; scripts calling methods before login; tests without a simulated user.

Understand the failure class

Background: error-invalid-user: "Invalid user" errors in Rocket.Chat — what they mean and how to fix them — this error's family across 2 libraries.

Related errors


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