RocketChat/Rocket.Chat · error · Meteor.Error
error-invalid-user
error-invalid-user
Error message
Invalid user
What it means
The /archive slash command resolves the executing user with Users.findOneById(userId, { username, name }) and requires isRegisterUser - which per core-typings means the user document must have both username and name defined. A missing user record (userId no longer in the users collection) or an incomplete user doc (no name or no username) fails with 'error-invalid-user' before any room logic runs.
Source
Thrown at apps/meteor/server/slashcommands/archiveroom/server.ts:38
let room;
if (channel === '') {
room = await Rooms.findOneById(message.rid);
if (room?.name) {
channel = room.name;
}
} else {
channel = channel.replace('#', '');
room = await Rooms.findOneByName(channel);
}
if (!userId) {
return;
}
const user = await Users.findOneById(userId, { projection: { username: 1, name: 1 } });
if (!user || !isRegisterUser(user)) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'archiveRoom' });
}
if (!room) {
void api.broadcast('notify.ephemeralMessage', userId, message.rid, {
msg: i18n.t('Channel_doesnt_exist', {
channelName: channel,
lng: settings.get('Language') || 'en',
}),
});
return;
}
if (!(await roomCoordinator.getRoomDirectives(room.t).allowMemberAction(room, RoomMemberActions.ARCHIVE, userId))) {
throw new Meteor.Error('error-room-type-not-archivable', `Room type: ${room.t} can not be archived`);
}
if (!(await hasPermissionAsync(userId, 'archive-room', room._id))) {
throw new Meteor.Error('error-not-authorized', 'Not authorized');View on GitHub (pinned to b2c16d5842)
Solutions
- Verify the user record exists and has both username and name before dispatching commands
- Backfill missing name or username fields on imported users
- Terminate sessions of deleted users so stale commands cannot fire
- Re-run the command from a healthy account after fixing the user document
Example fix
// before
const user = await Users.findOneById(userId, { projection: { username: 1, name: 1 } });
if (!user || !isRegisterUser(user)) throw new Meteor.Error('error-invalid-user', 'Invalid user');
// after - guard at the caller so the command gets a complete user
if (!user || user.username === undefined || user.name === undefined) {
return notifyUser('Your profile is incomplete (name/username missing); fix it before using /archive');
} Defensive patterns
Strategy: validation
Validate before calling
const user = await Users.findOneById(userId, { projection: { username: 1, name: 1 } });
if (!user || user.username === undefined || user.name === undefined) {
return refuse('Your user record is incomplete (missing name or username)');
}
runCommand('/archive', room); Type guard
const isRegisterUser = (u: { username?: string; name?: string } | null | undefined): u is { username: string; name: string } =>
Boolean(u && u.username !== undefined && u.name !== undefined); Try / catch
catch (err) {
if (err instanceof Meteor.Error && err.error === 'error-invalid-user') {
// session references a missing or incomplete user: log out and re-authenticate
} else throw err;
} Prevention
- Backfill name and username on imported users before enabling slash commands
- Kill sessions of deleted users promptly
- Require complete profiles (name) for accounts allowed to run moderation commands
When it happens
Trigger: Running /archive from a session whose user was deleted between connection and command processing; users created by imports or bots without a name field; token or session reuse after the account was removed.
Common situations: Deleted-but-still-connected sessions; bulk-imported users missing profile names; broken user-creation extensions that omit required fields.
Related errors
- error-room-type-not-archivable
- error-not-authorized
- error-user-not-found
- error-room-type-not-unarchivable
- department-not-found
AI-assisted analysis of RocketChat/Rocket.Chat@b2c16d5842 (2026-08-18).
Data as JSON: /api/errors/cb4268aba49806a4.
Report an issue: GitHub.