{"record":{"id":"b1239ba7bd164b15","repo":"RocketChat/Rocket.Chat","slug":"error-code-required","errorCode":"error-code-required","errorMessage":"Code required","messagePattern":"Code required","errorType":"error_code","errorClass":"MeteorError","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/services/room/service.ts","lineNumber":207,"sourceCode":"\t\tif (isOmnichannelRoom(room) && !room.open) {\n\t\t\tthrow new MeteorError('room-closed', 'Room is closed', { method: 'joinRoom' });\n\t\t}\n\n\t\tif (!(await Authorization.canAccessRoom(room, user))) {\n\t\t\tthrow new MeteorError('error-not-allowed', 'Not allowed', { method: 'joinRoom' });\n\t\t}\n\n\t\tif (\n\t\t\tFederationActions.shouldPerformFederationAction(room) &&\n\t\t\t!isUserNativeFederated(user) &&\n\t\t\t!(await FederationMatrix.canUserAccessFederation(user))\n\t\t) {\n\t\t\tthrow new MeteorError('error-not-authorized-federation', 'Not authorized to access federation', { method: 'joinRoom' });\n\t\t}\n\n\t\tif (isRoomWithJoinCode(room) && !(await Authorization.hasPermission(user._id, 'join-without-join-code'))) {\n\t\t\tif (!joinCode) {\n\t\t\t\tthrow new MeteorError('error-code-required', 'Code required', { method: 'joinRoom' });\n\t\t\t}\n\n\t\t\tconst isCorrectJoinCode = !!(await Rooms.findOneByJoinCodeAndId(joinCode, room._id, {\n\t\t\t\tprojection: { _id: 1 },\n\t\t\t}));\n\n\t\t\tif (!isCorrectJoinCode) {\n\t\t\t\tthrow new MeteorError('error-code-invalid', 'Invalid code', { method: 'joinRoom' });\n\t\t\t}\n\t\t}\n\n\t\treturn addUserToRoom(room._id, user);\n\t}\n\n\tasync beforeLeave(room: IRoom): Promise<void> {\n\t\tFederationActions.blockIfRoomFederatedButServiceNotReady(room);\n\t}\n","sourceCodeStart":189,"sourceCodeEnd":225,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/services/room/service.ts#L189-L225","documentation":"In join(), rooms protected by a join code (isRoomWithJoinCode) require a joinCode argument unless the user holds the join-without-join-code permission. When no joinCode is passed and the permission is absent, join throws Meteor error-code-required ('Code required', method 'joinRoom').","triggerScenarios":"Calling join({ room, user }) with no joinCode on a join-code-protected room while the user lacks join-without-join-code.","commonSituations":"Clients not surfacing the join-code prompt; scripts/integrations calling join without a code; permission changes removing the bypass from a role.","solutions":["Prompt the user for the room's join code and pass it as joinCode","Grant the role join-without-join-code where policy allows bypassing codes","Confirm the room actually requires a code (isRoomWithJoinCode) before demanding input"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"import { Authorization } from '@rocket.chat/core-services';\n\nconst needsCode = isRoomWithJoinCode(room) && !(await Authorization.hasPermission(uid, 'join-without-join-code'));\nif (needsCode && !joinCode) {\n  // prompt for the code instead of calling join() without it\n  return promptForJoinCode(room);\n}","typeGuard":"const requiresJoinCode = async (room: IRoom, uid: string): Promise<boolean> =>\n  isRoomWithJoinCode(room) && !(await Authorization.hasPermission(uid, 'join-without-join-code'));","tryCatchPattern":"try {\n  await roomService.join({ room, user });\n} catch (err) {\n  if (err?.error === 'error-code-required') {\n    // ask for the code, then retry once with joinCode supplied\n    const joinCode = await promptForJoinCode(room);\n    return roomService.join({ room, user, joinCode });\n  }\n  throw err;\n}","preventionTips":["Detect join-code rooms in the UI and show the code prompt before calling join","Trim user-supplied codes before sending","Grant join-without-join-code to trusted roles where policy allows"],"tags":["rooms","join","join-code","rocket-chat"],"backgroundTag":"join-code-required","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}