1

我正在尝试验证 Meteor 中的允许挂钩。以下是我所做的。

let EasyPost = Npm.require('node-easypost')(process.env.EASYPOST_KEY);

Addresses.allow({
  insert(userId, document) {
    check(document, Addresses.simpleSchema());
    EasyPost.createAndVerify(document, function (err, result) {
      if (err) {
        // insert should not be allowed.
      } else {
        document = Object.assign(document, {
          easypost: result
        })
      }
    })
  }
});

但是,我不能使用return false,因为它是异步操作。有一个更好的方法吗?

4

1 回答 1

0

看看这里这个问题中解释的wrapAsync方法。我从未真正在部分中使用过它,因为我更喜欢使用方法,但它应该可以工作,但如果不是,你总是可以切换到方法,并在那里使用它。allow

于 2016-01-05T15:55:24.987 回答