Meteor 用户没有电子邮件地址

Meteor user has no email address

使用simple schema and accounts-password。我试图在启动时添加一个初始帐户,但没有出现电子邮件和密码。

Schemas.User = new SimpleSchema({
  username: {
    type: String,
    regEx: /^[a-z0-9A-Z_]{3,15}$/
  },
  emails: {
    type: [Object],
    optional: true
  },
  "emails.$.address": {
    type: String,
    regEx: SimpleSchema.RegEx.Email
  },
  "emails.$.verified": {
    type: Boolean
  },
  profile: {
    type: Schemas.UserProfile,
    optional: true
  }
});

Meteor.startup(function () {
  Meteor.users.remove({});
  if (Meteor.users.find().count() == 0) {
    Accounts.createUser({
      username: "newuser",
      emails: [{address:"test@test.com", verified:true}],
      password:"mypassword"
    });
  }
  console.log(Meteor.users.find().fetch());
}

给我们:

[{_id: 'xxx', username:'newuser'}]

没有电子邮件或密码。没有错误。想法?

本系统的新用户只能由现有用户添加,所以我没能测试用户提交表单。

Accounts.createUser 将字符串作为 email 属性 用于 options 参数。至于密码问题,可能是由于您的架构中缺少 services 属性。添加到您的 Schemas.User 以下内容 属性:

Schemas.User = new SimpleSchema({
  // ...
  services: {
      type: Object,
      optional: true,
      blackbox: true
  }
}

最后,Accounts.createUser 文档(首先参见 link)指出:

On the client, you must pass password and at least one of username or email — enough information for the user to be able to log in again later. On the server, you do not need to specify password, but the user will not be able to log in until it has a password (eg, set with Accounts.setPassword).

这似乎不适用于你的情况,但作为最后的手段,请尝试在之后调用 Accounts.setPassword(userId, "mypassword")Meteor.createUser.

返回用户的id