RocketChat/Rocket.Chat · error · Meteor.Error
error-invalid-user
error-invalid-user
Error message
Invalid user
What it means
The getSingleMessage Meteor-method wrapper throws 'error-invalid-user' when Meteor.userId() is null — no authenticated user on the DDP connection. The room-access check inside the helper never runs because the user id itself is missing.
Source
Thrown at apps/meteor/server/meteor-methods/messages/getSingleMessage.ts:37
if (!msg?.rid) {
return null;
}
if (!(await canAccessRoomIdAsync(msg.rid, userId))) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'getSingleMessage' });
}
return msg;
};
Meteor.methods<ServerMethods>({
async getSingleMessage(mid) {
check(mid, String);
const uid = Meteor.userId();
if (!uid) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'getSingleMessage' });
}
return getSingleMessage(uid, mid);
},
});
View on GitHub (pinned to b2c16d5842)
Solutions
- Guard on Meteor.userId(); re-login when null
- Use GET /v1/chat.getMessage with an authenticated token instead
- Retry once after re-authentication for deep-link flows
Example fix
// before
Meteor.call('getSingleMessage', mid);
// after
if (!Meteor.userId()) {
// re-authenticate, then retry
}
Meteor.call('getSingleMessage', mid); Defensive patterns
Strategy: validation
Validate before calling
if (!Meteor.userId()) {
// re-authenticate before resolving deep-linked messages
} else {
Meteor.call('getSingleMessage', mid);
} Try / catch
try {
const msg = await Meteor.callAsync('getSingleMessage', mid);
} catch (e) {
if ((e as Meteor.Error).error === 'error-invalid-user') {
// re-login then retry once; otherwise show unavailable
}
} Prevention
- Guard deep-link flows with a session check before fetching
- Use GET /v1/chat.getMessage with an auth token for integration flows
- Match on the error code, not the 'Invalid user' message text
When it happens
Trigger: Meteor.call('getSingleMessage', mid) from an anonymous connection or one whose token expired/was revoked.
Common situations: Deep-link handling in tabs that lost their session; integrations fetching single messages over DDP without login.
Related errors
AI-assisted analysis of RocketChat/Rocket.Chat@b2c16d5842 (2026-08-18).
Data as JSON: /api/errors/e84eadb9afabf6ff.
Report an issue: GitHub.