How to get Meteor.Call to return value for template?

后端 未结 4 1443
情歌与酒
情歌与酒 2020-12-02 12:11

I\'ve tried to understand this post regarding this concept, however, I\'m failing to get it. I have the following simple setup:

/server/test.js
Meteor.method         


        
4条回答
  •  南方客
    南方客 (楼主)
    2020-12-02 13:07

    I went for a ghetto solution. But, it works for me, which is what matters, to me. Below is my code, which, in concept, I think, solves OP's problem.

    In the client's main.js:

    Meteor.setInterval(function() {
        confirmLogin();
    
    }, 5000); 
    

    This runs the confirmLogin() function every five seconds.

    The confirmLogin function (in the client's main.js):

    function confirmLogin() {
        Meteor.call('loggedIn', function (error, result) {
            Session.set("loggedIn", result);
        });
    
    }
    

    The loggedIn method (in the server's main.js):

    loggedIn: function () {
        var toReturn = false;
        var userDetails = Meteor.user();
        if (typeof userDetails["services"] !== "undefined") {
            if (typeof userDetails["services"]["facebook"] != "undefined") {
                toReturn = true;
            }
        }
    
        return toReturn;
    },
    

    The relevant helper:

    loggedIn: function () {
        return Session.get("loggedIn");
    }
    

提交回复
热议问题