RocketChat/Rocket.Chat · error · Meteor.Error

error-invalid-user

error-invalid-user

Error message

Invalid user

What it means

The setEmail method wrapper requires an authenticated user: it calls Meteor.userAsync() and throws error-invalid-user when the result is null, before delegating to setEmailFunction.

Source

Thrown at apps/meteor/server/meteor-methods/users/setEmail.ts:47

		return email;
	}

	if (!(await setEmail(user._id, email))) {
		throw new Meteor.Error('error-could-not-change-email', 'Could not change email', {
			method: 'setEmail',
		});
	}

	return email;
};

Meteor.methods<ServerMethods>({
	async setEmail(email) {
		methodDeprecationLogger.method('setEmail', '9.0.0', '/v1/users.updateOwnBasicInfo');
		const user = await Meteor.userAsync();

		if (!user) {
			throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'setEmail' });
		}

		return setEmailFunction(email, user);
	},
});

RateLimiter.limitMethod('setEmail', 1, 1000, {
	userId(/* userId*/) {
		return true;
	},
});

View on GitHub (pinned to b2c16d5842)

Solutions

  1. Guard the call with Meteor.userId() on the client and re-login when null
  2. For server-side flows use REST /v1/users.updateOwnBasicInfo with an auth token instead of the DDP method
  3. Catch error-invalid-user and route the user back to login
Defensive patterns

Strategy: validation

Validate before calling

const user = Meteor.userId();
if (!user) {
  throw new Error('Login required before changing email');
}

Try / catch

catch (err) {
  if (err instanceof Meteor.Error && err.error === 'error-invalid-user') {
    Meteor.logout();
    redirectToLogin();
  }
}

Prevention

When it happens

Trigger: Meteor.call('setEmail', email) executed with no logged-in user - expired login token, post-logout call, or a server-side invocation without user context.

Common situations: Session expiring between page load and form submit; custom clients or scripts calling the method cold; test harnesses 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/23de5c9c117f4f8d. Report an issue: GitHub.