Can't we do Meteor.userAsync() in pubs anymore?

Hi all,

in my app I do policy checks for subs using await Meteor.userAsync() quite often. Like so:

Meteor.publish("vmessage.count", async function publish() {
  const user = await Meteor.userAsync();
  ...
}

Problem is that now I get a bunch of

Meteor.userId can only be invoked in method calls or publications.

I know in principle I could also fall back to using this.userId and fetch the user details from the db, but the old pattern with await Meteor.userAsync()

  1. is working pretty fine in meteor 2.14
  2. is spread all over my project (would take a significant amout of time for me to refactor this, since I determine a users tenancy from the user object, in order to filter out the docs related to that tenantId)

Is this an uncommon design pattern or am I missing something? Any help or comments highly appreciated :slight_smile:

I wonder whether it’s something similar to this issue: [ Meteor v3 ] -`Email.sendAsync` fails, also impacting `accounts-password` methods · Issue #12963 · meteor/meteor · GitHub. It looks like in Email.sendAsync the scope of this gets lost (see line https://github.com/meteor/meteor/blob/release-3.0/packages/email/email.js#L113, where this is undefined).

I suggest creating a repo with a quick reproduction of the issue and submitting it.

Yes, looks like the current DDP context is lost. I actually found that the issue is related to use of collection-hooks in meteor 3.0-beta, here’s my bugreport (including a minimal repo for reproducing the issue): https://github.com/Meteor-Community-Packages/meteor-collection-hooks/issues/307

Demo app will start working again fine when removing collection-hooks (there’s something hooked into Meteor.publish, I suspect this causes the issue) or after downgrading to meteor 2.14.

I’m glad to hear you found the culprit. As far as I understand, collection-hooks is still pretty much work in progress.

Hi, this should be fixed now in beta.4.