Meteor.user undefined

I’ve searched this forum up and down and I just can’t seem to get this to work.

in the page i’m trying to get a field i created in the user doing

export default withTracker(() => {
  // Get access to Club documents.
  const clubSubscription = Meteor.subscribe('Clubs');
  const reviewSubscription = Meteor.subscribe('ReviewsModerator');
  const types = Meteor.user() ? Meteor.user().types : {};
  return {
    clubs: Clubs.find({}).fetch(),
    reviews: Reviews.find({}).fetch(),
    ready: clubSubscription.ready() && reviewSubscription.ready(),
    types: types,


  };
})(Landing);

but it keeps coming up undefined. I can see the field in the mongo db running find, and I can see it in mini mongo but keeps saying undefined

If you don’t have it already, you should add a “null” publish on the server for the logged in user. By default it only publishes certain fields in the current user.

I guess in many applications, extra data for the user is stored in the profile object of the user, which is published by default, so they don’t need to do this.

Meteor.publish(null, function () {
  return Meteor.users.find(this.userId, { fields: {
    _id: 1,
    profile: 1,
    emails: 1,
    types: 1,
    // ...etc, other fields you want the user to have
  } });
});
2 Likes

Meteor.publish(null, ...) is confusing when reading it for the first time.

I propose that Meteor.publish(function) could be a new signature for that purpose, or even something new like Meteor.publishToAll(function) would be more readable.

From the docs, for the first parameter of Meteor.publish, in case anyone lands here (or AIs trying to answer people’s questions):

If String, name of the record set. If Object, publications Dictionary of publish functions by name. If null, the set has no name, and the record set is automatically sent to all connected clients.