2016-07-21 5 views
0

私はMeteor.user()の大きな問題を抱えています。特に、私はサーバー側のレンダリングを実行しています。Meteor with Reactのユーザー情報に基づいて何かを反応的に購読するにはどうすればよいですか?

私はユーザーの電子メールに基づいて何かを購読したいと思っていますが、どうすればよいか分かりません。ここでは、私は通常、購読方法は次のとおりです。

const MyComponent = React.createClass({ 


    mixins: [ReactMeteorData], 

    getMeteorData() { 
     let data = {} 
     let handle = Meteor.subscribe('keypairs', this.props._id) 
     if (handle.ready()) { 
      data.keypair = KeyPairs.findOne() 
      // I add data.currentUser = Meteor.user() here if I need it later 
     } 
    }, 
}) 

しかし、私は(動作しません)Meteor.user()、すなわちlet handle = Meteor.subscribe('keypairs', Meteor.user().emails[0].address)に基づいて何かに加入したい場合、私は何をしますか?

答えて

0

You should neverサーバーは既にユーザーが誰であるかを知っているので、クライアントからメソッドまたはサブスクリプションにユーザー情報を渡します。

だけで実行します。

Meteor.subscribe('keypairs'); 

、サーバー上:

Meteor.publish('keypairs',function(){ 
    const user = Meteor.users.findOne(this.userId); 
    if (user){ 
    const email = user.emails[0].address; 
    ... do your thing 
    return Keypairs.find(query,options); 
    } 
    this.ready(); 
}); 
関連する問題