如何 return 对上面的函数为真

How to return true to a function above

我正在使用 firebase onauth() 方法,但需要 return 将函数的值设为上面调用它的函数。我如何才能 return 实现上面的函数,如代码所示:

    signedIn: function(){

        ref.onAuth(function(authData) {
          if (authData) {
            console.log("Authenticated with uid:", authData.uid);
            return true
          } else {
            console.log("Client unauthenticated.")
          }
        });
    }

使用承诺:

function signedIn(){
    var deferred = $q.defer();
    ref.onAuth(function(authData) {
      if (authData) {
        console.log("Authenticated with uid:", authData.uid);
        deferred.resolve();
        return true
      } else {
        console.log("Client unauthenticated.")
        deferred.reject();
      }
    });
    return deferred.promise;
}

signedIn().then(function () {
    alert('Authenfication successful!');
});