facebooktwitter-bootstrapmeteormeteor-useraccounts

Meteor login with facebook


I have a meteor app, with packages :

useraccounts:bootstrap; 
service-configuration; 
accounts-facebook; 

The facebook side was configured to allow requests from localhost. When using the register/signin with facebook from the atForm, a popup appears

EDIT

The popup is actually not empty but displays a message 'login complete, click to close' but closed fast because that's how I configured it on the facebook side.

And the console logs an error:

Exception while invoking method 'login' undefined

EDIT

Here is the service conf:

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

EDIT

Here is the client side code :

Template.atForm.events({
    'click #at-facebook': function(event) {
        console.log("facebook click");
        Meteor.loginWithFacebook({
          requestPermissions: ['email', 'user_friends']
          }, function (err) {
          if (err)
            Session.set('errorMessage', err.reason || 'Unknown error');
        });
    }
});

EDIT When registering with facebook the user created is as follow :

{ createdAt: Thu Jan 21 2016 16:00:08 GMT+0100 (CET),
I20160121-16:00:08.108(1)?   _id: 'Kgs3WswMdB9hsxMfp',
I20160121-16:00:08.108(1)?   services: 
I20160121-16:00:08.108(1)?    { facebook: 
I20160121-16:00:08.108(1)?       { accessToken: 'removed',
I20160121-16:00:08.108(1)?         expiresAt: 1458562023670,
I20160121-16:00:08.109(1)?         id: 'removed',
I20160121-16:00:08.109(1)?         email: 'removed',
I20160121-16:00:08.109(1)?         name: 'Mathieu Kudla',
I20160121-16:00:08.109(1)?         first_name: 'Mathieu',
I20160121-16:00:08.110(1)?         last_name: 'Kudla',
I20160121-16:00:08.110(1)?         link: 'https://www.facebook.com/app_scoped_user_id/removed/',
I20160121-16:00:08.110(1)?         gender: 'male',
I20160121-16:00:08.110(1)?         locale: 'fr_FR',
I20160121-16:00:08.110(1)?         age_range: [Object] } } }

This seems to indicate that the facebook handshake was successful?

What is causing that error? Thanks :)


Solution

  • Ok I kinda solved it.

    I digged in the log-in attempts and noticed that the oauth service was not properly paired with the user. I don't know why that is or if there is a better solve but I added the line :

    if (user.services) { var service = _.pairs(user.services)[0]; }
    

    to my onCreateUser hook and appended the user object properly before returning it. It seems to have done the trick but I don't know what I was not doing properly the first time...