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:
Meteor.methods({
'getUserId': function() {
return this.userId;
}
});
Meteor.methods({
'getUser': function() {
return this.user;
}
});
Does that sound right, or am I on the wrong track?
I’m trying this:
Meteor.call('getUser', (error, user) => {
if (error) {
// Handle the error
} else {
console.log(user)
}
…but I’m getting undefined
back in the user object. I’ve never created Meteor functions. Am I missing something?
ignl
April 28, 2024, 8:13pm
4
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.
ignl
April 29, 2024, 1:39pm
6
Ok maybe it’s something 3.0 related then I haven’t migrated yet
denyhs
April 29, 2024, 2:30pm
7
Thanks for reporting this. I’ll try to simulate it and see what’s happening.
1 Like