简体   繁体   中英

Internal Server Error when using Meteor.loginWithFacebook

Using the service-configuration and accounts-facebook packages, after clicking on the facebook button and logging in from the Facebook authorization window that pops up, we're getting an Internal server error when performing a Meteor.loginWithFacebook .

This was tested on a very basic example, what is causing this error?

Template.login.events({
    'click .btn-facebook': function (ev) {
        Meteor.loginWithFacebook({}, function(error) {
            if(error) {
                throw new Meteor.Error('Facebook login failed: ', error);
            }
        })
    }
});

/server/lib/config/social.js

Meteor.startup(function() {

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

})

Error (server side)

Exception while invoking method 'login' undefined

Error (client side)

Error: Internal server error [500]
    at _.extend._livedata_result (http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:4964:23)
    at onMessage (http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:3725:12)
    at http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:2717:11
    at Array.forEach (native)
    at Function._.each._.forEach (http://localhost:3000/packages/underscore.js?0a80a8623e1b40b5df5a05582f288ddd586eaa18:156:11)
    at _.extend._launchConnection.self.socket.onmessage (http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:2716:11)
    at REventTarget.dispatchEvent (http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:156:22)
    at SockJS._dispatchMessage (http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:1141:10)
    at SockJS._didMessage (http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:1199:18)
    at WebSocket.SockJS.websocket.that.ws.onmessage (http://localhost:3000/packages/ddp.js?d1840d3ba04c65ffade261f362e26699b7509706:1346:17)

I had the same issue, and solved it like this :

After checking that you have configured your schema as described here :

Schema.User = new SimpleSchema({
    _id: {
        type: String
    }
    ...
});

You should add the second part into an Accounts.onCreateUser like this, into server/accounts.js for example :

Accounts.onCreateUser(function (options, user) {
  if (user.services.facebook) {
    user.emails = [{
      address: user.services.facebook.email,
      verified: true
    }];
  }
  return user;
});

It will append the facebook email to the newly created account. The error should disapear.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM