Meteor Collections 架构不允许 Google 身份验证
Meteor Collections schema not allowing Google authentication
我正在使用 MeteorJS 构建一个简单的用户帐户。用户只能使用 Google 选择 login/register。如果他们是第一次注册,用户将在使用他们的用户帐户进行身份验证后被提示填写他们的个人资料信息。
我正在使用 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 的新手,我不确定这个错误是什么意思。我似乎找不到有关该问题的任何文档。我已经尝试修改我的 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 架构进行验证,而不是仅作为对象进行验证。
似乎此选项之一为空或不存在。
createdAt,profile,username,services.
就像错误说它正在验证但不存在一样,例如,您正在尝试验证配置文件对象,但没有配置文件对象,因此架构上没有任何内容。
When the modifier option is true
这部分是因为默认情况下,所有密钥都是必需的。设置 optional: true
。所以要看看 login/registrato 工作流程的问题出在哪里。将选项更改为 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
}
});
我正在使用 MeteorJS 构建一个简单的用户帐户。用户只能使用 Google 选择 login/register。如果他们是第一次注册,用户将在使用他们的用户帐户进行身份验证后被提示填写他们的个人资料信息。
我正在使用 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 的新手,我不确定这个错误是什么意思。我似乎找不到有关该问题的任何文档。我已经尝试修改我的 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 架构进行验证,而不是仅作为对象进行验证。
似乎此选项之一为空或不存在。
createdAt,profile,username,services.
就像错误说它正在验证但不存在一样,例如,您正在尝试验证配置文件对象,但没有配置文件对象,因此架构上没有任何内容。
When the modifier option is true
这部分是因为默认情况下,所有密钥都是必需的。设置 optional: true
。所以要看看 login/registrato 工作流程的问题出在哪里。将选项更改为 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
}
});