Add passcode functionality to secure meeting

Hello everyone, I am facing some strange things with the JitsiMeetExternalAPI room passcode functionality

I have tried to integrate passcode functionality to secure my meeting using JitsiMeetExternalAPI.

I have created one meeting with 4 participants and sent a passcode to the email addresses with a videoconference link now the first participant is joined as a moderator and set the meeting passcode but another participant also joined without adding a passcode.

also, the first-time participant can join the meeting without adding a passcode but if I restart the same meeting then a passcode pop will be opened.

here is the code I have done for the set passcode

    api.addEventListener('participantRoleChanged', function (event) {
      if (event.role === 'moderator') {
        api.executeCommand('password', meetingPasscode);
      } else {
        setTimeout(() => {
          api.addEventListener('passwordRequired', () => {
            api.executeCommand('password', meetingPasscode);

          api.addEventListener('videoConferenceJoined', () => {
            setTimeout(function () {
              api.executeCommand('password', meetingPasscode);
            }, 300);
        }, 10);