Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用Node.js对DDP客户端进行身份验证_Javascript_Node.js_Meteor_Ddp - Fatal编程技术网

Javascript 使用Node.js对DDP客户端进行身份验证

Javascript 使用Node.js对DDP客户端进行身份验证,javascript,node.js,meteor,ddp,Javascript,Node.js,Meteor,Ddp,node.js DDP客户端(使用)调用DDP服务器上的方法insertMessage,该方法将文档保存到mongodb Meteor.methods({ 'insertMessage': function(msg) { Messages.insert({'msg':msg, 'userId': userId}) } }) 我们怎么能只允许经过身份验证的DDP客户端插入包含其唯一标识符的文档用户ID,而不能伪造其他人的用户ID?我看了一下,但似乎成功的身份验证提

node.js DDP客户端(使用)调用DDP服务器上的方法
insertMessage
,该方法将文档保存到mongodb

Meteor.methods({
    'insertMessage': function(msg) {
        Messages.insert({'msg':msg, 'userId': userId})
    }
})
我们怎么能只允许经过身份验证的DDP客户端插入包含其唯一标识符的文档
用户ID
,而不能伪造其他人的
用户ID
?我看了一下,但似乎成功的身份验证提供了一个令牌,这个令牌可以用于我们的目的吗

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})
    }
})

在服务器中,您有以下参数

流星法

这个是.userId

此文件为.setUserId

这是一种模仿

这是解锁

这个连接


在服务器中,您有以下参数

流星法

这个是.userId

此文件为.setUserId

这是一种模仿

这是解锁

这个连接

在方法中,将是登录用户的用户id,如果用户未登录,则为
null
。在方法中,将是登录用户的用户id,如果用户未登录,则为
null
Meteor.methods({
    'insertMessage': function(msg) {
        userId = this.userId;
        Messages.insert({'msg':msg, 'userId': userId})
    }
})