Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: ... Use this.userId in publish functions #10

Open
jiku opened this issue Apr 2, 2015 · 7 comments
Open

Error: ... Use this.userId in publish functions #10

jiku opened this issue Apr 2, 2015 · 7 comments

Comments

@jiku
Copy link
Contributor

jiku commented Apr 2, 2015

With

channelById: (id) ->
      try
        GoogleApi.get "/youtube/v3/search", { params: { part: "snippet", channelId: id }}, (err, data) ->
      catch err
        console.log err

I get

err [Error: Meteor.userId can only be invoked in method calls. Use this.userId in publish functions.]

When using GoogleApi in a package. Any ideas? Tried with a clean 1.0.5 app and package X. Only dependencies in package X are what's needed to log in to Google, which it does just fine. Tests run fine too. I'm using the same credentials successfully in other apps, so I'm pretty sure it's not a permissions, scope, etc, problem.

@tmeasday
Copy link
Member

tmeasday commented Apr 7, 2015

Hi @jiku - The package assumes you are running in a method call (so it knows which user's credentials to use when talking to google).

Can you try GoogleApi.get(..., {user: Meteor.users.findOne(this.userId)}) or the like? Does that fix the problem for you?

I don't think there's any way that from inside a library we can detect that we are running in the context of a publish function, so we'll need you to pass the user in no matter what. We should document this better I think.

@jiku
Copy link
Contributor Author

jiku commented Apr 8, 2015

Thanks, that fixed it. =)
I've added if (options.user) delete options.user; before the API call in google-api-sync.js, but maybe that's something Meteor strips off before the call is made?

@tmeasday
Copy link
Member

tmeasday commented Apr 8, 2015

I'm not sure what you mean @jiku ?

@jiku
Copy link
Contributor Author

jiku commented Apr 9, 2015

Sorry, should've added some context

...
if (options.user) delete options.user; // Avoid sending user? Or will Meteor discard extra HTTP.call options being passed to the API?
HTTP.call(method, this._host + '/' + path, options, function(error, result) {
...

I'm not that proficient with Meteor/Node yet, so it's a bit unclear to me if this became an issue with meteor/meteor#1703

@tmeasday
Copy link
Member

Good pickup @jiku. It probably doesn't do anything as request and HTTP don't have a user option AFAIK, but we shouldn't pass it through. #11

@jiku
Copy link
Contributor Author

jiku commented Apr 10, 2015

Cool. :) I made a PR if that's useable.

@ghost
Copy link

ghost commented Oct 14, 2015

Is this issue supposed to be closed @jiku? I'm getting the [Error: Meteor.userId can only be invoked in method calls. Use this.userId in publish functions.] error in my publish-functions, and when I try to implement your code I get a 500 error regarding refreshtokens.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants