【发布时间】:2014-09-13 09:27:37
【问题描述】:
node.js DDP 客户端(使用node-ddp)调用 DDP 服务器上的方法 insertMessage,将文档保存到 mongodb。
Meteor.methods({
'insertMessage': function(msg) {
Messages.insert({'msg':msg, 'userId': userId})
}
})
如何只允许经过身份验证的 DDP 客户端插入包含其唯一标识符 userId 的文档,而不能伪造其他人的 userId?我查看了ddp-login,但似乎成功的身份验证提供了一个令牌,这个令牌可以用于我们的目的吗?
Meteor.methods({
'insertMessage': function(msg) {
// Check that the current user's userId (how can we do this?)
userId = getUserId()
Messages.insert({'msg':msg, 'userId': userId})
}
})
【问题讨论】:
-
在方法中,
this.userId将是登录用户的用户 ID,如果用户未登录,则为null。
标签: javascript node.js meteor ddp