我正在使用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模式進行驗證,而不僅僅是作爲對象進行驗證。