node.js DDP 客户端(使用 node-ddp )调用 DDP 服务器上的方法 insertMessage
,该方法将文档保存到 mongodb。
Meteor.methods({
'insertMessage': function(msg) {
Messages.insert({'msg':msg, 'userId': userId})
}
})
如何才能只允许经过身份验证的 DDP 客户端插入包含其唯一标识符 userId
的文档,而不能伪造其他人的 userId
?我看了ddp-login但似乎成功的身份验证会给出一个 token ,这个 token 可以用于我们的目的吗?
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})
}
})
最佳答案
在服务器中,你有这个参数..
Meteor.methods
this.userId
this.setUserId
this.isSimulation
this.unblock
this.connection
Meteor.methods({
'insertMessage': function(msg) {
userId = this.userId;
Messages.insert({'msg':msg, 'userId': userId})
}
})
关于javascript - 使用 Node.js 验证 DDP 客户端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25815894/