2015-04-01 37 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 
    } 
});