RocketChat/Rocket.Chat · error · Meteor.Error
error-invalid-user
error-invalid-user
Error message
Invalid user
What it means
The getChannelHistory Meteor-method wrapper throws 'error-invalid-user' when Meteor.userId() is null — channel history requires an authenticated caller because room-read authorization (Authorization.canReadRoom) is evaluated per user. The method is deprecated since 9.0.0 in favor of GET /v1/channels.history.
Source
Thrown at apps/meteor/server/meteor-methods/messages/getChannelHistory.ts:163
return {
messages: messages || [],
firstUnread,
unreadNotLoaded,
};
}
return {
messages: messages || [],
};
};
Meteor.methods<ServerMethods>({
async getChannelHistory({ rid, latest, oldest, inclusive, offset = 0, count = 20, unreads, showThreadMessages = true }) {
methodDeprecationLogger.method('getChannelHistory', '9.0.0', '/v1/channels.history');
check(rid, String);
if (!Meteor.userId()) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'getChannelHistory' });
}
const fromUserId = Meteor.userId();
if (!fromUserId) {
return false;
}
return getChannelHistory({ rid, fromUserId, latest, oldest, inclusive, offset, count, unreads, showThreadMessages });
},
});
View on GitHub (pinned to b2c16d5842)
Solutions
- Check Meteor.userId() first; re-authenticate when null
- Switch to GET /v1/channels.history with an auth token (deprecation target)
- Make history loaders retry once after a re-login instead of failing the panel
Example fix
// before
Meteor.call('getChannelHistory', { rid });
// after
if (!Meteor.userId()) {
// re-login before loading history
}
Meteor.call('getChannelHistory', { rid }); Defensive patterns
Strategy: validation
Validate before calling
if (!Meteor.userId()) {
// re-login before loading history
} else {
Meteor.call('getChannelHistory', { rid, latest, oldest, inclusive, offset, count });
} Try / catch
try {
const history = await Meteor.callAsync('getChannelHistory', params);
} catch (e) {
if ((e as Meteor.Error).error === 'error-invalid-user') {
// session expired mid-scroll: re-auth and reload the history panel
}
} Prevention
- Check Meteor.userId() in loaders that run automatically (infinite scroll)
- Migrate to GET /v1/channels.history with a token (deprecation target)
- Retry history loads once after re-login instead of leaving the panel empty
When it happens
Trigger: Meteor.call('getChannelHistory', { rid, latest, oldest, ... }) from an expired, revoked, or anonymous DDP session.
Common situations: Infinite-scroll / history loaders firing after token expiry; integrations fetching history over DDP without login; long-lived dashboards that outlive their session.
Related errors
AI-assisted analysis of RocketChat/Rocket.Chat@b2c16d5842 (2026-08-18).
Data as JSON: /api/errors/a523ff9aa8d3516e.
Report an issue: GitHub.