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?