RocketChat/Rocket.Chat · error · Error

invalid user

Error message

invalid user

What it means

Final guard in NpsModule.viewSubmit: the user is destructured with a default of {} (user: { _id: userId, roles } = {}), the vote is recorded via NPS.vote, and only afterwards does the check run — so a payload without user._id throws 'invalid user'. Note the ordering: NPS.vote is attempted before the guard fires.

Source

Thrown at apps/meteor/server/modules/core-apps/nps.module.ts:65

		const [npsId] = Object.keys(state);

		const bannerId = viewId.replace(`${npsId}-`, '');

		const {
			[npsId]: { 'nps-score': score, comment },
		} = state;

		await NPS.vote({
			npsId,
			userId,
			comment: String(comment),
			roles,
			score: Number(score),
		});

		if (!userId) {
			throw new Error('invalid user');
		}

		await Banner.dismiss(userId, bannerId);
	}
}

View on GitHub (pinned to b2c16d5842)

Solutions

  1. Always include the acting user (with _id) on viewSubmit payloads
  2. Validate payload.user before dispatch
  3. If you already hit this, audit NPS vote records — the vote call runs before the guard and may have recorded data without a user
  4. Fix client identity propagation so the interaction carries Meteor.userId()

Example fix

// before
await nps.viewSubmit({ payload: { view: { state, id: viewId } } }); // user missing -> 'invalid user'

// after
await nps.viewSubmit({
  user: { _id: Meteor.userId()!, roles: Meteor.user()?.roles },
  payload: { view: { state, id: viewId } },
});
Defensive patterns

Strategy: validation

Validate before calling

const hasActingUser = (p: any): boolean => Boolean(p?.user?._id);

Type guard

const hasUserId = (p: unknown): p is { user: { _id: string } } =>
  typeof p === 'object' && p !== null && typeof (p as any).user?._id === 'string';

Prevention

When it happens

Trigger: A viewSubmit payload whose user is undefined or lacks _id, e.g. submissions from custom clients that omit identity, or middleware stripping the user field.

Common situations: Bots or scripts submitting NPS modals without an acting user; refactors of the payload envelope; testing payloads built by hand.

Related errors


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