1

尝试创建用户时出现以下错误:

Exception while invoking method 'createUser' Error: When the modifier option 
is true, validation object must have at least one operator

这是我调用该createUser方法的方式:

Template.register.events({
  "submit #register_form": function(event) {
    event.preventDefault();

    var $form   = $("#register_form");
    var attr    = {};
    var profile = {};


    // We gather form values, selecting all named inputs
    $("input[name]", $form).each(function(idx) {
      var $input = $(this);
      var name   = $input.attr("name");


      if (name == "email" || name == "password") {
        attr[ name ] = $input.val();
      }
      else if (name != "repeat_password") {
        profile[ name ] = $input.val();
      }
    });
    attr.profile = profile;


    // Creating user account (Cf Accounts module)
    Accounts.createUser(attr, function(error) {
      console.log(error);
    }); 
  },
});

attr具有以下值: 在此处输入图像描述

这是我定义users架构的方式:

// Setting up Simple Schema (cf module)
var profile_schema = new SimpleSchema({
  firstname: {
    type:   String,
    regEx:  /^[a-z0-9A-Z_]{3,15}$/
  },
  lastname: {
    type:   String,
    regEx:  /^[a-z0-9A-Z_]{3,15}$/
  },
  celular: {
    type:     String,
    optional: true,
  },
});


var schema = new SimpleSchema({
  emails: {
    type:   [Object],
  },
  "emails.$.address": {
    type:   String,
    regEx:  SimpleSchema.RegEx.Email
  },
  "emails.$.verified": {
    type:   Boolean
  },
  profile: {
    type:     profile_schema,
    optional: true,
  },
  createdAt: {
    type:   Date
  },
});


// Attaching Simple Schema to the users collection (Cf collection2 module)
Meteor.users.attachSchema(schema);

我找不到不正确的地方。任何建议都是最受欢迎的!

4

1 回答 1

2

添加我的评论作为可见性的答案

您需要将服务对象添加到您的用户架构中,如下所示

services: { 
    type: Object,
    blackbox: true 
}

即使您没有使用任何 oAuth,您也需要添加它,因为 Meteor 为电子邮件登录添加了“服务”。你应该永远拥有它。

于 2015-09-13T19:59:03.487 回答