2

ユーザーのプロファイル情報が表示されません。理由はありますか?

サーバー:

Meteor.publish("userData", function () {
    return Meteor.users.find({_id: this.userId},
        {fields: {'profile': 1}});
});
Meteor.publish("allUsers", function () {
    //TODO: For testing only, remove this
    return Meteor.users.find({}, {fields: {'profile': 1}});
});

クライアント :

Meteor.autosubscribe(function () {
    Meteor.subscribe('allUsers',null , function() { console.log(Meteor.users.find().fetch()) });
    Meteor.subscribe('userData', null, function() { console.log(Meteor.user())});
});

....

Accounts.createUser({email:email,password:password, profile: {name: name}},function(error){
    ...
});

私のコンソールは、最初のものは_idとメールのみ、2番目のものは未定義のオブジェクトを出力しました。私のserver.jsには正常に機能する名前検証があるため、プロファイル情報(私の場合は名前)が機能しているようです:

Accounts.onCreateUser(function(options, user) {
    if(options.profile.name.length<2)
        throw new Meteor.Error(403, "Please provide a name.");
    return user;
});

何か不足していますか?

ありがとう!

4

3 に答える 3

3

複数のサブスクリプションを使用する場合、最初のサブスクリプションのみが重要です。同じコレクションを含む場合、2 番目のサブスクリプションは最初のサブスクリプションと競合するため無視されます。

ただし、代わりにこれを行うこともできます。

サーバ:

var debugmode = false; //set to true to enable debug/testing mode
Meteor.publish("userData", function () {
    if(debugmode) {
        return Meteor.users.find({}, fields: {'profile': 1}});
    }
    else
    {
        return Meteor.users.find({_id: this.userId},{fields: {'profile': 1}});
    }
});

クライアント:

Meteor.autosubscribe(function () {
    Meteor.subscribe('userData', null, function() { console.log(Meteor.user()); console.log(Meteor.users.find({}).fetch());});
});
于 2013-01-28T10:42:46.580 に答える
3

問題が見つかりました:

onCreateUser 関数では、オプションからのプロファイル情報をユーザー オブジェクトに追加する必要があるため、関数は次のようになります。

Accounts.onCreateUser(function(options, user) {
    if(options.profile.name.length<2)
        throw new Meteor.Error(403, "Please provide a name.");
    if (options.profile)
    user.profile = options.profile;
    return user;
});
于 2013-01-28T15:44:27.733 に答える
1

~/server/createAccount.js に配置されている、私が使用している回避策は次のとおりです。私が抱えていた問題は、プロファイルが定義されていない場所でエラーが発生することです。これは、アカウントの作成時にプロファイルを作成することで問題を解決するようです。

これが役に立つことを願っています。以下のコメントで、githubの問題のコメントでそれを見つけました:

// BUGFIX via https://github.com/meteor/meteor/issues/1369 @thedavidmeister
// Adds profile on account creation to prevent errors from profile undefined on the profile page
Accounts.onCreateUser(function(options, user) {
  user.profile = options.profile ? options.profile : {};
  return user;
});
于 2014-01-06T12:33:52.263 に答える