I am trying to access the collection names posts to check if the current user has already liked or not . If liked then showing liked button in different color.
The issue is the function is called two times.
isLiked: function() {
let self = this;
console.log();
Meteor.call('posts.isLiked', self._id, (error, result) => {
console.log(result);
return result;
});
}
The above function calls the posts.isLiked as below -
'posts.isLiked': (_id) => {
check(_id, String);
if (!Meteor.user()) {
throw new Meteor.Error(401, 'You need to be signed in to continue');
}
if (!_id) {
throw new Meteor.Error(422, '_id should not be blank');
}
return (Posts.find( { _id: _id , already_voted: { "$in" : [Meteor.userId()]} }).count() == 1);
}
Expected -
the console to show output 1 time
Actual -
The console shows output 2 times.