RocketChat/Rocket.Chat · error · Meteor.Error

error-invalid-user

error-invalid-user

Error message

Invalid user

What it means

uploadImportFile's login gate: `Meteor.userId()` returning null triggers error-invalid-user. The method writes an uploaded file into server storage and the imports collection, so an authenticated user is mandatory.

Source

Thrown at apps/meteor/server/meteor-methods/import/uploadImportFile.ts:72

	});

	await instance.updateProgress(ProgressStep.FILE_LOADED);
};

declare module '@rocket.chat/ddp-client' {
	// eslint-disable-next-line @typescript-eslint/naming-convention
	interface ServerMethods {
		uploadImportFile(binaryContent: string, contentType: string, fileName: string, importerKey: string): void;
	}
}

Meteor.methods<ServerMethods>({
	async uploadImportFile(binaryContent, contentType, fileName, importerKey) {
		methodDeprecationLogger.method('uploadImportFile', '9.0.0', '/v1/uploadImportFile');
		const userId = Meteor.userId();

		if (!userId) {
			throw new Meteor.Error('error-invalid-user', 'Invalid user', 'uploadImportFile');
		}

		if (!(await hasPermissionAsync(userId, 'run-import'))) {
			throw new Meteor.Error('error-action-not-allowed', 'Importing is not allowed', 'uploadImportFile');
		}

		await executeUploadImportFile(userId, binaryContent, contentType, fileName, importerKey);
	},
});

View on GitHub (pinned to b2c16d5842)

Solutions

  1. Authenticate and verify `Meteor.userId()` before uploading
  2. Re-login and retry on error-invalid-user
  3. Use POST /v1/uploadImportFile with auth headers for automation

Example fix

// before
Meteor.call('uploadImportFile', bin, 'text/csv', 'users.csv', 'csv', cb); // error-invalid-user

// after
if (!Meteor.userId()) { await relogin(); }
Meteor.call('uploadImportFile', bin, 'text/csv', 'users.csv', 'csv', cb);
Defensive patterns

Strategy: validation

Validate before calling

if (!Meteor.userId()) { await relogin(); }
Meteor.call('uploadImportFile', bin, contentType, fileName, 'csv', cb);

Try / catch

Meteor.call('uploadImportFile', bin, type, name, key, (err) => {
  if (err && (err as Meteor.Error).error === 'error-invalid-user') {
    // re-authenticate, then retry the upload once
  }
});

Prevention

When it happens

Trigger: Calling `Meteor.call('uploadImportFile', ...)` while logged out or after the DDP session/token expired; invoking from server code without a user context.

Common situations: Upload widgets that skip the login check when the session silently expired; headless scripts uploading exports without first authenticating.

Related errors


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