【发布时间】:2013-05-19 15:20:10
【问题描述】:
我目前正在为 Meteor 编写一个以服务器为中心的包,相关代码如下所示:
__meteor_bootstrap__.app.stack.unshift({
route: route_final,
handle: function (req,res, next) {
res.writeHead(200, {'Content-Type': 'text/json'});
res.end("Print current user here");
return;
}.future ()
});
这显然是一种比较老套的做事方式,但我需要创建一个 RESTful API。
如何从这里访问Meteor.userId()?文档说它只能从方法内部访问或发布。有什么办法解决吗?
我尝试过的事情:
- 使用
Meteor.publish("user", function() { user = this.userId() });从发布中捕获它 - 从 cookie 中获取令牌 + 用户 ID,并使用类似
Meteor.users.findOne({_id:userId,"services.resume.loginTokens.token":logintoken});的方式自行验证 - 创建一个名为
get_user_id的方法并从我下面的代码中调用它。
【问题讨论】:
标签: javascript meteor