開発中のアプリのユーザー プロファイル ページを作成しました。ユーザーがログインしているときはページが正常に機能しますが、誰もログインしていないときはテンプレートが空です。私の目標は、誰でも (アプリに登録していなくても) ユーザー プロファイルを表示できるようにすることです。
コードは次のとおりです。
出版物:
Meteor.publish('singleUser', function(userId) {
if (this.userId) {
var findById = Meteor.users.find(userId);
return findById.count() ? findById : 'undefined';
}
return [];
});
ルーター:
this.route('user_profile', {
path: '/users/:_id',
waitOn: function() {
return Meteor.subscribe('singleUser', this.params._id);
},
data: function() {
return Meteor.users.findOne({_id: this.params._id});
}
});
プロファイル テンプレート:
<template name="user_profile">
<h4>Username</h4>
<p>{{username}}</p>
<h4>User since:</h4>
<p>{{createdAtFormatted}}</p>
</template>
プロファイル ヘルパー:
Template.user_profile.helpers({
createdAtFormatted: function(){
return moment(this.createdAt).fromNow();
}
});
コードに何が欠けているのかわかりません。
ありがとう!