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