Meteor 3 - "Meteor.userId can only be invoked in method calls or publications."?

I’m working on updating my app to Meteor 3.0rc0.

I’m seeing this a lot, on the client, and also on the server in my GraphQL resolvers:

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

For example, in a GraphQL resolver on the server, this line throws:

 const userData = Meteor.user();

What’s a good way to handle this?

I’m getting the impression that I need to set up a couple of Meteor methods and then call them from an async context with await:

    'getUserId': function() {
        return this.userId;

    'getUser': function() {
        return this.user;

Does that sound right, or am I on the wrong track?

I’m trying this:'getUser', (error, user) => {
    if (error) {
        // Handle the error
    } else {

…but I’m getting undefined back in the user object. I’ve never created Meteor functions. Am I missing something?

You can just use Meteor.user() in client too to get user. Meteor.user() in server too instead of this.user.

With meteor 2, I could always use meteor.userId() in my resolvers. With meteor 3, I get a message saying it can only be used in a method or a publication.

Ok maybe it’s something 3.0 related then I haven’t migrated yet :slight_smile:

Thanks for reporting this. I’ll try to simulate it and see what’s happening.

1 Like

Here’s a small demo app.

  • Incorporates minor updates to Meteor Apollo Skeleton for Meteor 3
  • Does not require Meteor package swydo:apollo
  • Demonstrates that Meteor.user() cannot yet be accessed in resolvers