I'm trying to write a simple method that will return the email (or any other field) of a logged in user. I have autopublish turned off but whenever I try to access Meteor.user() in my displayField method I get undefined.
However, if I write a general function (outside of Meteor) it can access it and display it fine... what am I doing wrong??
Meteor.methods({
displayEmail: function () {
var user = Meteor.user();
if (!user)
throw new Meteor.Error(401, "you need to be logged in");
console.log(user.emails[0].address);
return user.emails[0].address;
}
});
My client side function:
Template.hello.greeting = function () {
var output = Meteor.call('displayEmail', function(error,id) {
if (error)
return alert(error.reason);
});
return output;
};
My template:
...
{{greeting}}
...
So like I said, the console.log(user.emails[0].address) works just fine, but I get a blank in my template...