RocketChat/Rocket.Chat · error · Meteor.Error
error-invalid-user
error-invalid-user
Error message
Invalid user
What it means
Thrown by 'e2e.fetchMyKeys' when there is no authenticated user. The method returns the caller's end-to-end encryption key pair via Users.fetchKeysByUserId(userId); without a session there is no user whose keys could be returned. The method is deprecated since 9.0.0 in favor of /v1/e2e.fetchMyKeys (named by its deprecation logger).
Source
Thrown at apps/meteor/server/meteor-methods/platform/fetchMyKeys.ts:19
import type { ServerMethods } from '@rocket.chat/ddp-client';
import { Users } from '@rocket.chat/models';
import { Meteor } from 'meteor/meteor';
import { methodDeprecationLogger } from '../../lib/deprecationWarningLogger';
declare module '@rocket.chat/ddp-client' {
// eslint-disable-next-line @typescript-eslint/naming-convention
interface ServerMethods {
'e2e.fetchMyKeys'(): { public_key?: string; private_key?: string };
}
}
Meteor.methods<ServerMethods>({
async 'e2e.fetchMyKeys'() {
methodDeprecationLogger.method('e2e.fetchMyKeys', '9.0.0', '/v1/e2e.fetchMyKeys');
const userId = Meteor.userId();
if (!userId) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'e2e.fetchMyKeys' });
}
return Users.fetchKeysByUserId(userId);
},
});
View on GitHub (pinned to b2c16d5842)
Solutions
- Restore the session (re-login) before requesting E2E keys
- Guard the call with Meteor.userId() and restart E2E setup after login
- Migrate to GET /v1/e2e.fetchMyKeys with an authenticated request (the method already logs this deprecation)
Example fix
// before
const keys = await Meteor.callAsync('e2e.fetchMyKeys');
// after
if (!Meteor.userId()) {
// E2E setup must wait for a session
return restartE2ESetupAfterLogin();
}
const keys = await Meteor.callAsync('e2e.fetchMyKeys'); Defensive patterns
Strategy: validation
Validate before calling
// client: E2E key retrieval requires a session
if (!Meteor.userId()) {
// defer E2E setup until after login
} 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 keys = await Meteor.callAsync('e2e.fetchMyKeys');
} catch (err) {
if (isMeteorError(err, 'error-invalid-user')) {
// restart E2E setup after re-authentication
} else {
throw err;
}
} Prevention
- Sequence E2E key fetch after login state is confirmed
- Migrate to GET /v1/e2e.fetchMyKeys for new code — the DDP method is deprecated in 9.0.0
When it happens
Trigger: Fetching E2E keys during encrypted-room setup from an expired session; calling the method during the login/logout transition; scripts invoking it without authentication.
Common situations: E2E key handshake on clients whose token expired; long-lived tabs resuming E2E setup; migrations to the REST endpoint in 9.x.
Related errors
AI-assisted analysis of RocketChat/Rocket.Chat@b2c16d5842 (2026-08-18).
Data as JSON: /api/errors/7edaddc5aa33ff3c.
Report an issue: GitHub.