The answer in - "What's going on with Meteor and Fibers/bindEnvironment()?" is very helpful however it could not help me resolve my issue.
Here is what I am doing :
- Login with google
- Call FunGoogle(user) from Accounts.onCreateUser
code:
SocialFunGoogle = function (user) {
var config = Accounts.loginServiceConfiguration.findOne({service: 'google'});
var opts = {
consumerKey: config.clientId,
consumerSecret: config.secret,
token: user.services.google.accessToken,
refreshToken: user.services.google.refreshToken
};
var gcontacts = new GoogleContacts(opts);
gcontacts.refreshAccessToken(opts.refreshToken, function (err, accessToken) {
if (err && err != null) {
console.log('gcontact.refreshToken, ', err);
return false;
} else {
console.log('gcontact.access token success!');
gcontacts.token = accessToken;
}
});
var fn = Meteor.bindEnvironment(function () {
var Fiber = Meteor.require('fibers');
var Future = Meteor.require('fibers/future');
var future = new Future();
setTimeout(function () {
return future.return(
Fiber(function () {
gcontacts.getContacts(
function (err, contact) {
contact = [{
name: 'S Sharma',
email: 'ssharma@gmail.com',
photoUrl: 'https://www.google.com/m8/feeds/photos/media/procrazium%40gmail.com/adf456aaaabbnndaa',
mime_type: 'image/*'
}, {
name: 'A Kapil',
email: 'kapil.a@gmail.com',
photoUrl: 'https://www.google.com/m8/feeds/photos/media/procrazium%40gmail.com/22aaaab555758bc37952',
mime_type: 'image/*'
}, {
name: 'A Kartik',
email: 'akrtik@gmail.com',
photoUrl: 'https://www.google.com/m8/feeds/photos/media/procrazium%40gmail.com/2f2aaa02aab00f7aa85a2',
mime_type: 'image/*'
}];
contact.map(function (c) {
SocialConnect.insert(c);
});
return contact;
});
}).run()
);
}, 500);
});
fn();
}
When I try logging in, my code throws the following errors.
Exception while invoking method 'login' TypeError: Cannot set property '_meteor_dynamics' of undefined
Error: Meteor code must always run within a Fiber. Try wrapping callbacks that you pass to non-Meteor libraries with Meteor.bindEnvironment
Can you please point out what am I doing here wrong?