node.js DDP 客户端(使用node-ddp)调用insertMessage
DDP 服务器上的方法,该方法将文档保存到 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})
}
})