【发布时间】:2016-02-13 05:44:09
【问题描述】:
我在处理这些看似微不足道的事情时遇到了麻烦,harrrr!
我有这个用户文档:
userData = {
account: {
type: 'free'
},
profile: {
name: 'Artem',
},
username: 'aaa@gmail.com',
password: '123'
};
我要发送的客户端:Accounts.createUser(userData);
然后服务器端我想检查帐户类型是否等于“免费”。如果没有 - 我想中止创建新用户(并希望在客户端抛出错误)
我在文档中发现了 2 个功能可能可以帮助我做到这一点:
-
Accounts.validateNewUser
问题:它接收到不包含
profile, username, password, email以外的属性的“修剪”用户对象。因此,我无法验证account.type,因为它在正在验证的用户对象上不存在。 -
Accounts.onCreateUser
问题:在创建通用用户对象后调用它,我无法取消在用户集合中插入新文档。它绝对需要返回用户文档。如果我返回
undefined它会在服务器上引发错误:Exception while invoking method 'createUser' Error: insert requires an argument
它也不允许抛出方法错误(因为它不是方法)->因此我无法记录错误客户端。
【问题讨论】:
-
如何将帐户类型数据作为配置文件对象的一部分发送?然后您将能够在
Accounts.validateNewUser中访问此值并进行验证。 -
奇怪的是你必须做那些花样。我已经提交了一个问题 - github.com/meteor/meteor/issues/6231
标签: meteor