(HTML/Js) 使用提示和承诺进行身份验证

(HTML/Js) Authentication Using Prompts and Promises

下面我有一些代码:

async function authenticateUser() {
        let authenticated = false;
        socketTx = io();
        socketRx = io.connect();

        var user = prompt("Please enter username", "");
        var pass = prompt("Please enter your password", "");

        socketTx.emit('authChannel', {username: user, password: pass});

        let promise = new Promise((resolve, reject) => {
              socketRx.on('authChannel', function(auth) {
                //console.log(auth);
                resolve(auth); 
              });
        });

        authenticated = await promise;
        console.log(authenticated)
        if (authenticated == false) {
          user;
          pass;
        } else {authenticated == true}
      }

socketTx 正在向 Node.js 中的服务器发送 user/pass 数据以进行 PAM 身份验证。 socketRx 收到 true/false 以判断用户是否已通过身份验证。

理想的行为是提示向用户发送垃圾邮件,直到提供正确的 "login" 信息。我想我在验证身份验证为假后再次调用变量 user/pass 时捕获了此行为,但提示不会显示第二次(或更多次)。我可以确认我在 console.log(authenticated).

收到了正确的信息

有什么明显的我遗漏的东西吗?

提前致谢。

根据评论:

async function authenticateUser() {
        let authenticated = false;
        socketTx = io();
        socketRx = io.connect();

        var user = prompt("Please enter username", "");
        var pass = prompt("Please enter your password", "");

        socketTx.emit('authChannel', {username: user, password: pass});

        let promise = new Promise((resolve, reject) => {
              socketRx.on('authChannel', function(auth) {
                //console.log(auth);
                resolve(auth); 
              });
        });

        authenticated = await promise;
        console.log(authenticated)
        if (authenticated == false) {
          authenticateUser(); // recall method
        } else {authenticated == true}
      }