so i'm creating user profile pages, , have gotten data current user working fine. issue i'm having current user can't see other users data.
i've looked @ can find on web haven't find answer has helped me, many different ways of doing 1 thing.
my publish
meteor.publish('allusers', function(user){ return meteor.users.find({_id: this.userid},{ fields: { profile: 1, emails:1, username: 1 } }); }); my router
router.route('/profile/:_id', { name: 'profile', waiton: function(){ return meteor.subscribe('allusers')}, data: function(){ var user = this.params._id; return meteor.users.findone({_id: user}); }, }); profile template
<template name='profile'> username: {{username}}<br> email: {{email}} {{log}} {{#with profile}} full name: {{name}} {{log}} {{/with}} </template> helper
template.profile.helpers({ name: function(){ return this.name; }, username: function(){ return this.username; }, email: function(){ return this.emails[0].address; }, log: function(){ console.log(this); } }); and how i'm linking other users
<a href="/profile/{{owner}}">{{username}}</a>
owner being users _id:
the log output current user showing data though log output of other user empty object. though grabbing right _id.
in allusers publication, find user {_id: this.userid}. this.userid id of user subscribing. means you're publishing user's own data, , not data of other users. if wanted publish of users, you'll want use .find({}, {fields: ...}) instead.
for applications more few users, publishing users not idea, instead can publish 1 user:
meteor.publish("userbyid", function (requesteduserid) { return meteor.users.find({_id: requesteduserid}, {fields: ...}); }); then when subscribe in router, pass in user id:
meteor.subscribe("userbyid", this.params._id);
Comments
Post a Comment