1

I am trying to validate on an allow hook in Meteor. The following is what I do.

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
        })
      }
    })
  }
});

However, I can't use return false because it is an asynchronous operation. Is there a better way to do this?

KFunk
  • 2,956
  • 22
  • 33
corvid
  • 10,733
  • 11
  • 61
  • 130

1 Answers1

0

Take a look at wrapAsync method as explained here or in this question. I never actually used it in allow sections, because I prefer to use methods, but it should work, but if it's not, you can always switch to methods, and use it there.

Community
  • 1
  • 1
Adam Wolski
  • 5,448
  • 2
  • 27
  • 46