0

我想在我的代码中返回 isValid 和凭据,但验证不返回 isValid 和凭据。我必须做什么来确定该变量的范围?

 const validating = mySqlDb.query(
              'SELECT * FROM users WHERE username = ? ' +
            'AND password = ?;',
              [username, password], function(error, results, fields) {
                console.log(results);
                if (results.length === 1) {
                  const isValid = true;
                  const credentials = {
                    account: username,
                    login: 'now',
                  };
                  return {isValid, credentials};
                }
                if (results.length === 0) {
                  const isValid = false;
                  const credentials = null;
                  return {isValid, credentials};
                }
              },
          );
          return {validating};
4

0 回答 0