简体   繁体   中英

Attaching schema to Meteor.users

I'm trying to customise my Meteor.users schema:

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

And when I call:

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

Console returned:

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

What am i missing here?

Accounts.createUser() expects extra info to come across in a profile key.

Use:

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

And set up an Accounts.onCreateUser() function on the server:

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

docs

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM