Meteor.loginWithFacebook中的内部服务器错误

时间:2017-03-07 12:21:01

标签: meteor

我在Meteor很新。

我使用此回购https://github.com/ciprian88m/meteor-1.3-social-network玩了一下,我尝试通过Facebook添加登录,但收到以下错误:"内部服务器错误"。

这是我的代码:

signup.js:

     `Template.signup.events({
        'click #at-facebook': function(event, collback, response) {
           Meteor.loginWithFacebook({
     requestPermissions: ['email', 'public_profile', 'user_friends']
  }, function(error){
     if (error)
         console.log(error);
     else
         Router.go('/chat');
  });
  },

  'click #at-google': function(event, collback, response) {
        Meteor.loginWithGoogle({}, function(error) {
              if(error) {
                  throw new Meteor.Error('Facebook login failed: ', error);
              }
          });
      }
});`

accounts.js:

`AccountsTemplates.configure({
  postSignUpHook: (userId, info) => {
     let fullName = `${info.profile.firstName} ${info.profile.lastName}`,
          dob      = new Date(info.profile.yearOfBirth, info.profile.monthOfBirth -1,     info.profile.dayOfBirth),
    user     = Meteor.users.findOne({ _id: userId });

      Meteor.users.update({ _id: userId }, {
     $set: {
      "profile.birthday": dob,
      "profile.fullName": fullName,
       "profile.meta.primaryEmail": user.emails[0].address
    }
  });
}

});

 ServiceConfiguration.configurations.remove({
   service: 'facebook'
  });

      ServiceConfiguration.configurations.insert({
     service: 'facebook',
     "appId": "***",
   "secret": "****"
   });

  ServiceConfiguration.configurations.update(
    { "service": "google" },
    {
      $set: {
        "clientId": "***",
        "secret": "***",
        loginStyle: "popup"
      }
    },
    { upsert: true }
  );
  Accounts.onCreateUser(function (options, user) {
    if (user.services.facebook) {
      user.emails = [{
        address: user.services.facebook.email
    }];
    }
    return user;
  });

`

users.js:

         ```
    let Schemas = {};

     Schemas.Meta = new SimpleSchema({
    isPublicProfile: {
   type: Boolean,
    autoValue: function () {
    if (this.isInsert) { return false; }
  }
},
 primaryEmail: { type: String, optional: true },
profileImage: { type: String, optional: true },
signedUpOn: {
  type: Date,
  autoValue: function () {
    if (this.isInsert) { return new Date(); }
    else { this.unset(); }
  }
}
 });

Schemas.UserProfile = new SimpleSchema({
 firstName:    { type: String },
lastName:     { type: String },
fullName:     { type: String, optional: true },
 gender:       { type: String, allowedValues: ['male', 'female'] },
dayOfBirth:   { type: String },
monthOfBirth: { type: String },
  yearOfBirth:  { type: String },
birthday:     { type: Date, optional: true },
 location:     { type: String, optional: true },
meta:         { type: Schemas.Meta, optional: true }
});

Schemas.Users = new SimpleSchema({
 _id: {
   type: String
 },
  username:            { type: String },
  profile:             { type: Schemas.UserProfile, optional: true },
  emails:              { type: Array },
  "emails.$":          { type: Object },
"emails.$.address":  { type: String, regEx: SimpleSchema.RegEx.Email },
  "emails.$.verified": { type: Boolean },
 services:            { type: Object, optional: true, blackbox: true },
createdAt: {
  type: Date,
autoValue: function () {
  if (this.isInsert) { return new Date(); }
  else { this.unset(); }
 }
 }
});

Meteor.users.attachSchema(Schemas.Users);

1 个答案:

答案 0 :(得分:0)

在你的accounts.js中,配置插入有点奇怪。

ServiceConfiguration.configurations.insert({
     service: 'facebook',
     "appId": "***",
   "secret": "****"
   });

而是试试这个,这类似于你已经为google配置的内容:

ServiceConfiguration.configurations.upsert(
    {service: "facebook"},
    {
      $set: {
        appId: "***",
        secret: "***"
      }
    }
  );