I want the Facebook accessToken that is stored in my user's document on the client. Following the meteor documentation, I should just add a new publish call.
In server.js:
Meteor.publish("access_token", function () {
return Meteor.users().find(
{ _id : Meteor.userId() },
{'services.facebook.accessToken': 1}
);
});
In client.js:
Meteor.subscribe("access_token");
Alright, here's where I get lost. Should the accessToken just show up in the Meteor.users collection now for the logged in user? Like:
var user = Meteor.users.findOne({ _id : Meteor.userId() });
console.log(user); // includes services.facebook.accessToken now
Obviously, I've tried the above and the accessToken doesn't show up. Yes, I've confirmed that the mongo document contains services.facebook.
So... do I create a new client collection and somehow hook it up to the new publish? How do I get the accessToken?
you should use "fields" keyword
Meteor.users.find({ _id: this.userId },
{ fields: { the-extra-fields-that-you-want-go-here: 1 } }
);
http://docs.meteor.com/#fieldspecifiers
You can publish the field you want:
Meteor.publish( null, function() {
Meteor.users.find({}, {fields: {profile: 1, username: 1, ...}})
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With