{"record":{"id":"00e7a3527ddff01e","repo":"RocketChat/Rocket.Chat","slug":"error-not-authorized-00e7a3","errorCode":"error-not-authorized","errorMessage":"Not authorized","messagePattern":"Not authorized","errorType":"error_code","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/meteor-methods/rooms/archiveRoom.ts","lineNumber":38,"sourceCode":"export const executeArchiveRoom = async (userId: string, rid: string) => {\n\tcheck(rid, String);\n\n\tconst user = await Users.findOneById(userId, { projection: { username: 1, name: 1 } });\n\tif (!user || !isRegisterUser(user)) {\n\t\tthrow new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'archiveRoom' });\n\t}\n\n\tconst room = await Rooms.findOneById(rid);\n\tif (!room) {\n\t\tthrow new Meteor.Error('error-invalid-room', 'Invalid room', { method: 'archiveRoom' });\n\t}\n\n\tif (!(await roomCoordinator.getRoomDirectives(room.t).allowMemberAction(room, RoomMemberActions.ARCHIVE, userId))) {\n\t\tthrow new Meteor.Error('error-direct-message-room', `rooms type: ${room.t} can not be archived`, { method: 'archiveRoom' });\n\t}\n\n\tif (!(await hasPermissionAsync(userId, 'archive-room', room._id))) {\n\t\tthrow new Meteor.Error('error-not-authorized', 'Not authorized', { method: 'archiveRoom' });\n\t}\n\n\treturn archiveRoom(rid, user);\n};\n\nMeteor.methods<ServerMethods>({\n\tasync archiveRoom(rid) {\n\t\tmethodDeprecationLogger.method('archiveRoom', '9.0.0', '/v1/channels.archive');\n\t\tconst userId = Meteor.userId();\n\t\tif (!userId) {\n\t\t\tthrow new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'archiveRoom' });\n\t\t}\n\n\t\treturn executeArchiveRoom(userId, rid);\n\t},\n});\n","sourceCodeStart":20,"sourceCodeEnd":55,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/meteor-methods/rooms/archiveRoom.ts#L20-L55","documentation":"Thrown when hasPermissionAsync(userId, 'archive-room', room._id) returns false: the user is valid, the room exists and its type allows archiving, but this user lacks the archive-room permission for that specific room. The permission is evaluated with the room id as scope, so both global role grants and room-scoped overrides apply.","triggerScenarios":"A plain member (not owner/moderator) calls archiveRoom; the archive-room permission was revoked from the user's role after the UI rendered; room-scoped permission settings deny the caller.","commonSituations":"Workspace policies limiting archive to owners/moderators; permission changes not propagated to the client UI; custom roles created without archive-room.","solutions":["Grant archive-room to the acting user's role (Administration > Permissions), globally or scoped to the room.","Have a user who holds the permission (room owner or admin) perform the archive.","Gate the archive action client-side on the same permission so the method is never called without it."],"exampleFix":"// before\nMeteor.call('archiveRoom', rid);\n\n// after\nif (hasPermission(Meteor.userId(), 'archive-room', rid)) {\n  Meteor.call('archiveRoom', rid);\n} else {\n  showToast('Not authorized to archive this room');\n}","handlingStrategy":"try-catch","validationCode":"// with the roles subscription active, mirror the server check:\nif (!hasPermission(Meteor.userId(), 'archive-room', rid)) {\n  // hide/disable the archive action instead of calling the method\n}","typeGuard":null,"tryCatchPattern":"try {\n  await Meteor.callAsync('archiveRoom', rid);\n} catch (e) {\n  if (e instanceof Meteor.Error && e.error === 'error-not-authorized') {\n    showToast('You are not allowed to archive this room');\n    return; // do not retry - a permission will not appear by retrying\n  }\n  throw e;\n}","preventionTips":["Mirror the server permission name ('archive-room') in client UI gating, including room scope.","Run archive automations under a role that always holds archive-room.","After permission changes, refresh the roles/authorization subscription before trusting client checks."],"tags":["rocket-chat","meteor","ddp","archive-room","permissions","authorization"],"backgroundTag":"permission-denied","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}