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