2017-08-23 3 views
0

アカウント作成、フィールドの公開、およびそのパブリケーションへの登録にユーザのカスタムフィールドを追加していますが、クライアント側ではMeteor.user().customFieldにアクセスできません。 meteor mongoから、私は、ユーザーが、私が追加された新しいカスタムフィールドを持っている作成していることを確認、その後Meteor.user()はクライアントにカスタムフィールドを表示していません

import { Random } from 'meteor/random' 
Accounts.onCreateUser((options, user) => { 
    const cond = assignUserCondition(); 
    user.enterTime= new Date(); 
    user.page = null; 
    user.passedQuiz= false; 
    user.exitStatus=null; 
    user.quizAttempts= 0; 
    user.condition= cond; 
    user.avatar= null; 
    user.score= 0; 
    user.bonus= 0; 
    user.lobbyTimeout= LOBBY_TIMEOUT; 
    user.gameId= null; 
    user.condInfo = {name: cond, 
     groupSize: (cond+'GROUPS_SIZE').split('.').reduce((o, i) => o[i], CONDITIONS_SETTINGS), 
     bonusConversion: (cond+'BONUS_CONVERSION').split('.').reduce((o, i) => o[i], CONDITIONS_SETTINGS), 
     N_ROUNDS: (cond+'N_ROUNDS').split('.').reduce((o, i) => o[i], CONDITIONS_SETTINGS), 
    }; 
    return user; 
}); 

は、だから私のimports/api/users/users.jsに私は次のコードを追加します。さて、imports/api/users/server/publications.jsに私は次のコードを持っている:

Tracker.autorun(function(){ 
    Meteor.subscribe('users.user'); 
}); 

ただし、クライアント側では、console.log(Meteor.user())のみいかなるなし_idusernameを示しています

import {Meteor} from 'meteor/meteor' 
Meteor.publish('users.user', function(currentUser) { 
    let user= Meteor.users.find({_id:currentUser}, { 
     fields: { 
      _id: 1, 
      enterTime: 1, 
      page: 1, 
      passedQuiz: 1, 
      exitStatus: 1, 
      quizAttempts:1, 
      condition:1, 
      avatar: 1, 
      score:1, 
      bonus: 1, 
      lobbyTimeout: 1, 
      gameId: 1, 
      conditionInfo: 1 
     } 
    }); 
    if (user) { 
     return user; 
    } 
    return this.ready(); 
}); 

また、私のimports/startup/client/index.jsに私は、サブスクリプションを持っています私のカスタムフィールドの。

答えて

4

お客様のsubscribeのクライアントからcurrentUserパラメータを渡していませんでした。しかし、クライアントは信頼されていないので、厳密にはno-noです(誰かがあなたのメソッドに別のユーザーの_idを簡単に送ることができます)。出版物を次のように書き換えてください:

import {Meteor} from 'meteor/meteor' 
Meteor.publish('users.user', function() { 
    if (this.userId) { 
    return Meteor.users.find(this.userId, { 
     fields: { 
     _id: 1, 
     enterTime: 1, 
     page: 1, 
     passedQuiz: 1, 
     exitStatus: 1, 
     quizAttempts:1, 
     condition:1, 
     avatar: 1, 
     score:1, 
     bonus: 1, 
     lobbyTimeout: 1, 
     gameId: 1, 
     conditionInfo: 1 
     } 
    }); 
    } 
    return this.ready(); 
}); 
+0

これで解決しました – amaatouq

関連する問題