将架构附加到 Meteor.users

Attaching schema to Meteor.users

我正在尝试自定义我的 Meteor.users 架构:

Schema.users = new SimpleSchema({
username: {
    type: String,
},
test:{
    type: String,
},
services: {
    type: Object,
    optional: true,
    blackbox: true
}
});

当我打电话时:

Accounts.createUser({username:"lionel",test:"123",password:"123"});

控制台返回:

Exception while invoking method 'createUser' Error: Test is required
......
Sanitized and reported to the client as: Test is required [400]

我在这里错过了什么?

Accounts.createUser() 期望在 profile 键中出现额外信息。

使用:

Accounts.createUser({username:"lionel",password:"123",profile: {test:"123"}});

并在服务器上设置一个Accounts.onCreateUser()函数:

Accounts.onCreateUser(function(options, user) {
  if (options.profile) user.test = options.profile.test;
  return user;
});

docs