同步呼叫(等待ad.authenticate)

如何进行异步调用?我尝试使用此代码:

computed: {
    componentInstance() {
      return () => import("../public/assets/gw/plugin/component.vue");
    }
  }

NPM:https://www.npmjs.com/package/activedirectory2 GitHub:https://github.com/jsumners/node-activedirectory/

谢谢!

zwj1590971 回答:同步呼叫(等待ad.authenticate)

您可以尝试使用Promise

let myPromise = new Promise((resolve,reject) => {
     ad.authenticate(username,password,function(err,auth) {
      if(err){
        console.log('ERROR: '+JSON.stringify(err));
        fail_found = err.name;
        reject(fail_found)
        return;
      }

      if(auth){
        console.log('Authenticated!');
        resolve('Authenticated!');
      }else{
        console.log('Authenticated Faliled');
        fail_found = 'No Authenticated ';
        reject(fail_found)
      }          
    });
  }
  console.log("Fails?: ",fail_found);
  reject(fail_found)
});

myPromise.then((successMessage) => {
 console.log(successMessage);
}).catch(err => console.log(err))

或者在文档的第一部分中显示 promiseWrapper

const AD = require('activedirectory2').promiseWrapper;
const config = { url: 'ldap://dc.domain.com',baseDN: 'dc=domain,dc=com',username: 'username@domain.com',password: 'password' }
const ad = new AD(config);
本文链接:https://www.f2er.com/3160383.html

大家都在问