2015-04-01 35 views
0

我正在使用MeteorJS构建一个简单的用户帐户。用户只能选择使用Google登录/注册。如果他们是第一次注册,用户将被提示在用他们的用户帐户进行身份验证后填写他们的个人资料信息。流星集合架构不允许Google身份验证

我使用Collections2来管理用户帐户的模式并将其连接到Meteor.users,这是在这里看到:

var Schemas = {}; 


Schemas.UserProfile = new SimpleSchema({ 
    firstName: { 
     type: String, 
     regEx: /^[a-zA-Z-]{2,25}$/, 
     optional: true 
    }, 
    lastName: { 
     type: String, 
     regEx: /^[a-zA-Z]{2,25}$/, 
     optional: true 
    }, 
    gender: { 
     type: String, 
     allowedValues: ['Male', 'Female'], 
     optional: true 
    } 
}); 


Schemas.User = new SimpleSchema({ 
    username: { 
     type: String, 
     regEx: /^[a-z0-9A-Z_]{3,15}$/ 
    }, 

    _id : { 
     type: String 
    }, 

    createdAt: { 
     type: Date 
    }, 
    profile: { 
     type: Object 
    }, 
    services: { 
     type: Object, 
     blackbox: true 
    }, 
    // Add `roles` to your schema if you use the meteor-roles package. 
    // Option 1: Object type 
    // If you specify that type as Object, you must also specify the 
    // `Roles.GLOBAL_GROUP` group whenever you add a user to a role. 
    // Example: 
    // Roles.addUsersToRoles(userId, ["admin"], Roles.GLOBAL_GROUP); 
    // You can't mix and match adding with and without a group since 
    // you will fail validation in some cases. 
    //roles: { 
    // type: Object, 
    // optional: true, 
    // blackbox: true 
    //} 
    // Option 2: [String] type 
    // If you are sure you will never need to use role groups, then 
    // you can specify [String] as the type 
    roles: { 
     type: [String], 
     optional: true 
    } 
}); 


Meteor.users.attachSchema(Schemas.users); 

当注册一个帐户,我得到的错误:

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

我是新来的流星,我不确定这个错误的含义。我似乎无法找到关于这个问题的任何文件。我已经尝试修改我的Meteor.users.allow和Meteor.users.deny权限,看看它是否有任何作用,但它似乎是我使用collections2软件包的一些基本问题。

更新 - 已解决:在 我的代码最底部这一个拼写错误造成错误:

在那里我有Meteor.users.attachSchema(Schemas.users); 应该已经Meteor.users.attachSchema(Schemas.User);

类似的还有什么@Ethaan发布,我应该将我的Schemas.User.profile类型转换为profile: { type: Schemas.UserProfile }

这样,我的用户配置文件设置将根据UserProfile模式进行验证,而不仅仅是作为对象进行验证。

回答

2

它看起来像这样的选项之一是null或dosnt存在。

createdAt,profile,username,services. 

像错误说的东西得到验证,但dosnt存在,比如你正在试图验证配置文件对象,但没有配置文件对象因此没有其在架构得到。

When the modifier option is true

这部分是因为默认情况下,所有的键都是必需的。设置optional: true。以便查看登录/注册工作流程中的问题。将该选项更改为false

例如,更改配置文件字段上的可选项。

Schemas.User = new SimpleSchema({ 
    username: { 
     type: String, 
     regEx: /^[a-z0-9A-Z_]{3,15}$/ 
    }, 

    _id : { 
     type: String 
    }, 

    createdAt: { 
     type: Date 
    }, 
    profile: { 
     type: Object, 
     optional:false, // for example 
    }, 
    services: { 
     type: Object, 
     blackbox: true 
    } 
});