2016-04-28 22 views
1

Facebookを使用してMeteor.jsアプリケーションに接続して登録しようとしています。私のログインテンプレートでは、これを行うためのボタンを置いています。私は関数Meteor.loginWithFacebook()を呼び出しますが、うまくいきません... Meteorが新しいユーザーを作成しようとしていて、ユーザー名情報を見つけられないと推測していますが、それを管理する方法はわかりません。私が持っているエラーMeteorでログインしてFacebookに登録するときの問題

'click #facebook-login': function(event) { 
    Meteor.loginWithFacebook({}, function(err){ 
     if (err) { 
      throw new Meteor.Error("Facebook login failed"); 
      Materialize.toast('Echec de connexion!', 4000); 
     } 
     else { 
      Router.go(Utils.pathFor('home')); 
      Materialize.toast('Bon retour parmis nous ' + Meteor.user().username + ' !', 5000); 
     } 
    }); 
} 

I20160428-12:44:56.099(2)? Exception while invoking method 'login' Error: Nom d'utilisateur is required 
I20160428-12:44:56.100(2)?  at getErrorObject (packages/aldeed_collection2-core/lib/collection2.js:437:1) 
I20160428-12:44:56.101(2)?  at [object Object].doValidate (packages/aldeed_collection2-core/lib/collection2.js:420:1) 
I20160428-12:44:56.101(2)?  at [object Object].Mongo.Collection. (anonymous function) [as insert] (packages/aldeed_collection2-core/lib/collection2.js:173:1) 
I20160428-12:44:56.101(2)?  at AccountsServer.Ap.insertUserDoc (packages/accounts-base/accounts_server.js:1250:25) 
I20160428-12:44:56.101(2)?  at AccountsServer.Ap.updateOrCreateUserFromExternalService (packages/accounts-base/accounts_server.js:1386:20) 
I20160428-12:44:56.102(2)?  at [object Object].Package (packages/accounts-oauth/oauth_server.js:55:1) 
I20160428-12:44:56.103(2)?  at packages/accounts-base/accounts_server.js:464:32 
I20160428-12:44:56.103(2)?  at tryLoginMethod (packages/accounts-base/accounts_server.js:241:14) 
I20160428-12:44:56.103(2)?  at AccountsServer.Ap._runLoginHandlers (packages/accounts-base/accounts_server.js:461:18) 
I20160428-12:44:56.103(2)?  at [object Object].methods.login (packages/accounts-base/accounts_server.js:524:27) 
I20160428-12:44:56.129(2)? Sanitized and reported to the client as: Nom d'utilisateur is required [400] 

ユーザスキーマ:ログインを呼び出すため

マイハンドラ

Globals.schemas.UserProfile = new SimpleSchema({ 
firstName: { 
    type: String, 
    regEx: /^[a-zA-Z-]{2,25}/, 
    optional: true, 
    label: "Prénom" 
}, 
lastName: { 
    type: String, 
    regEx: /^[a-zA-Z-]{2,25}/, 
    optional: true, 
    label: "Nom" 
}, 
birthDay: { 
    type: Date, 
    optional: true, 
    label: "Date de naissance", 
    min: new Date("1900-01-01T00:00:00.000Z"), 
    autoform: { 
     value: new Date("1900-10-18T00:00:00.000Z") 
    } 
}, 
gender: { 
    type: String, 
    allowedValues: ['M', 'F'], 
    optional: true, 
    label: "Genre", 
    autoform: { 
     options: [ 
      { 
       label: "Homme", 
       value: "M" 
      }, 
      { 
       label: "Femme", 
       value: "F" 
      } 
     ], 
     firstOption: "(Veuillez sélectionner une réponse)" 
    } 
}, 
level: { 
    type: Number, 
    autoValue: function() { 
     if (this.isInsert) { 
      return 1; 
     } 
    }, 
    autoform: { 
     omit: true 
    }, 
    min: 0, 
    max: 1000, 
    label: "Niveau" 
}, 
picture: { 
    type: String, 
    optional: true, 
    autoform: { 
     omit: true 
    }, 
    label: "Photo" 
} 
}); 

// Schéma principal 
Globals.schemas.User = new SimpleSchema({ 
username: { 
    type: String, 
    regEx: /^[a-z0-9A-Z_]{3,30}$/, 
    label: "Nom d'utilisateur" 
}, 
password: { 
    type: String, 
    label: "Mot de passe", 
    optional: true, 
    autoform: { 
     afFieldInput: { 
      type: "password" 
     } 
    } 
}, 
confirmation: { 
    type: String, 
    label: "Confirmation", 
    optional: true, 
    custom: function(){ 
     if(this.value !== this.field('password').value){ 
      return "passwordMissmatch"; 
     } 
    }, 
    autoform: { 
     afFieldInput: { 
      type: "password" 
     } 
    } 
}, 
emails: { 
    type: [Object], 
    optional: false, 
    label: "Adresses Email" 
}, 
"emails.$.address": { 
    type: String, 
    regEx: SimpleSchema.RegEx.Email, 
    label: "Adresses Email" 
}, 
"emails.$.verified": { 
    type: Boolean, 
    optional: true, 
    autoform: { 
     omit: true 
    } 
}, 
createdAt: { 
    type: Date, 
    autoValue: function() { 
     if (this.isInsert) { 
      return new Date; 
     } else { 
      this.unset(); 
     } 
    }, 
    autoform: { 
     omit: true 
    } 
}, 
profile: { 
    type: Globals.schemas.UserProfile, 
    optional: true 
}, 
services: { 
    type: Object, 
    optional: true, 
    blackbox: true, 
    autoform:{ 
     omit: true 
    } 
}, 
roles: { 
    type: Object, 
    optional: true, 
    blackbox: true, 
    autoform: { 
     omit: true 
    } 
} 
}); 

は、任意の助けのためのありがとうございました!

+0

私にはあなたが名前を必要とMeteor.usersコレクションのスキーマを定義したように見えます。 – aedm

+0

@aedmはい、私は持っていますが、このフィールドにFacebookのユーザー名を使用するようにMeteorにどのように伝えますか?これは私にとっては難しい部分です... –

+0

問題の説明にスキーマを含めてください。 – aedm

答えて

1

問題は、Meteor.usersにはusernameフィールドが必要であり、デフォルトでは含まれていないということです。ただし、このフィールドはFacebookのプロフィールから名前を取得することで生成できます。

Accounts.onCreateUser(function(options, user) { 
    user.username = user.services.facebook.name; 
    return user; 
}); 

http://docs.meteor.com/#/full/accounts_oncreateuser

+0

ありがとうございました。 Facebookアカウントのユーザー名を取得するのが難しい。私は電子メール、名字と姓だけを持っています... –

+0

実際にはGoogleのために働いていますが、私はまだFacebookに問題がありますが、明白なエラーがないので、理由はわかりません... –

関連する問題