Custom fields on the user collection

Kind of a weird question.

I added some custom fields to the user collection. I’m publishing them like so:

Meteor.publish('currentUser', function() {
  if(this.userId) {
    return Meteor.users.find({
      _id: this.userId
    }, {
      fields: {
        servers: 1,
        games: 1,
        profile: 1,
        services: 1
      }
    })
  } else {
    this.ready();
  }
});

I’m subscribing to the publication in the client’s main.js.

  Meteor.subscribe('currentUser');

The first time Meteor.user() is called, it doesn’t include the custom fields. All subsequent requests do.

As a result, I have to have a bunch of login in the frontend checking to see if the objects exist before using them.

Is there a way to ensure the fields will be present on the first request?

The first time Meteor.user() is called, it doesn’t include the custom fields. All subsequent requests do.

Are you waiting for the subscription to become ready?

Something along these lines might help:

  const handle = Meteor.subscribe("currentUser");
  const loading = !handle.ready();

Worked line a charm, thanks so much!