【问题标题】:Usage of asynchronous validation within an allow hook在允许挂钩中使用异步验证
【发布时间】:2016-01-15 05:58:48
【问题描述】:

我正在尝试验证 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,因为它是一个异步操作。有没有更好的方法来做到这一点?

【问题讨论】:

  • 使用承诺?哪个函数是异步的?

标签: javascript asynchronous meteor easypost


【解决方案1】:

查看wrapAsync 方法,如herein this question 所述。我从未在allow 部分实际使用过它,因为我更喜欢使用方法,但它应该可以工作,但如果不是,你可以随时切换到方法,并在那里使用它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-04-19
    • 2012-06-07
    • 1970-01-01
    • 2011-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-16
    相关资源
    最近更新 更多