0

node.js DDP クライアント ( node-ddpinsertMessageを使用) は、ドキュメントを mongodb に保存する DDP サーバー上のメソッドを呼び出します。

Meteor.methods({
    'insertMessage': function(msg) {
        Messages.insert({'msg':msg, 'userId': userId})
    }
})

userId認証された DDP クライアントのみが、一意の識別子 を含むドキュメントを挿入できるようにし、他の誰かの を偽造できないようにするにはどうすればよい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})
    }
})
4

1 に答える 1

4

サーバーには、このパラメーターがあります..

Meteor.methods

this.userId

this.setUserId

this.isシミュレーション

this.unblock

この接続

Meteor.methods({
    'insertMessage': function(msg) {
        userId = this.userId;
        Messages.insert({'msg':msg, 'userId': userId})
    }
})
于 2014-09-13T00:59:30.147 に答える