除了使用url令牌作为其他答案之外,您还可以使用cookie:
添加一些允许您设置cookie并在服务器端读取它们的软件包:
meteor add mrt:cookies thepumpinglemma:cookies
然后,您便可以将cookie与您的登录状态同步起来
客户端
Tracker.autorun(function() { //Update the cookie whenever they log in or out cookie.set("meteor_user_id", Meteor.userId()); cookie.set("meteor_token", localStorage.getItem("Meteor.loginToken"));});服务器端
在服务器端,您只需要检查此cookie是否有效(使用Iron路由器)
Router.route('/somepath/:fileid', function() { //Check the values in the cookies var cookies = new cookies( this.request ), userId = cookies.get("meteor_user_id") || "", token = cookies.get("meteor_token") || ""; //Check a valid user with this token exists var user = Meteor.users.findOne({ _id: userId, 'services.resume.loginTokens.hashedToken' : Accounts._hashLoginToken(token) }); //If they're not logged in tell them if(!user) return this.response.end("Not allowed"); //Theyre logged in! this.response.end("You're logged in!");}, {where:'server'});


