RocketChat/Rocket.Chat · error · Meteor.Error
error-invalid-room
error-invalid-room
Error message
The rid field is invalid
What it means
After the permission check, findOrCreateInvite verifies the caller actually has a subscription in the target room and that the room document exists (Rooms.findOneById). Either failure throws error-invalid-room with message 'The rid field is invalid' and field rid, meaning the rid is well-formed but points to a room the user cannot invite into (no subscription) or that does not exist.
Source
Thrown at apps/meteor/server/lib/rooms/invites/findOrCreateInvite.ts:52
return false;
}
if (!invite.rid) {
throw new Meteor.Error('error-the-field-is-required', 'The field rid is required', {
method: 'findOrCreateInvite',
field: 'rid',
});
}
if (!(await hasPermissionAsync(userId, 'create-invite-links', invite.rid))) {
throw new Meteor.Error('not_authorized');
}
const subscription = await Subscriptions.findOneByRoomIdAndUserId(invite.rid, userId, {
projection: { _id: 1 },
});
if (!subscription) {
throw new Meteor.Error('error-invalid-room', 'The rid field is invalid', {
method: 'findOrCreateInvite',
field: 'rid',
});
}
const room = await Rooms.findOneById(invite.rid);
if (!room) {
throw new Meteor.Error('error-invalid-room', 'The rid field is invalid', {
method: 'findOrCreateInvite',
field: 'rid',
});
}
if (settings.get('ABAC_Enabled') && room?.abacAttributes?.length) {
throw new Meteor.Error('error-invalid-room', 'Room is ABAC managed', {
method: 'findOrCreateInvite',
field: 'rid',
});View on GitHub (pinned to b2c16d5842)
Solutions
- Verify the caller has a subscription in the room (join the room) before creating invites
- Confirm the room still exists with Rooms.findOneById(rid)
- Use a fresh rid from the room document, not a cached id from another session or workspace
Example fix
// before
await findOrCreateInvite(userId, { rid, days, maxUses });
// after
const sub = await Subscriptions.findOneByRoomIdAndUserId(rid, userId, { projections: { _id: 1 } });
if (!sub) throw new Meteor.Error('error-invalid-room', 'Join the room before creating invites');
await findOrCreateInvite(userId, { rid, days, maxUses }); Defensive patterns
Strategy: validation
Validate before calling
const [sub, room] = await Promise.all([
Subscriptions.findOneByRoomIdAndUserId(invite.rid, userId, { projections: { _id: 1 } }),
Rooms.findOneById(invite.rid, { projections: { _id: 1 } }),
]);
if (!sub || !room) {
throw new Meteor.Error('error-invalid-room', 'Join the room before creating an invite');
}
await findOrCreateInvite(userId, invite); Try / catch
try {
await findOrCreateInvite(userId, invite);
} catch (err) {
if (err instanceof Meteor.Error && err.error === 'error-invalid-room' && err.details?.field === 'rid') {
// user is not a member of the room or room is gone — prompt to join
}
throw err;
} Prevention
- Have bots join channels before generating invite links
- Clear cached rids after workspace migrations
- Only offer invite creation inside rooms the user has joined
When it happens
Trigger: Passing a rid for a room the user never joined (subscription lookup returns null), or a rid that matches no Rooms document — deleted room, id from another workspace, or a DM where the caller was removed. Both the subscription check (line 52) and the room-existence check (line 59) share this code.
Common situations: Invites created for archived rooms the user was removed from; workspace data migrated with new room ids while clients cached old ones; bot accounts creating invites without first joining the channel.
Related errors
- invalid-room
- error-invalid-room
- error-invalid-room
- error-invalid-subscription
- error-the-field-is-required
AI-assisted analysis of RocketChat/Rocket.Chat@b2c16d5842 (2026-08-18).
Data as JSON: /api/errors/fd6d7658edce7bf9.
Report an issue: GitHub.