Null userdId in backend


#1

Hello, I got this issue, in a frontend I subscribe to a collection and in the backend I search for the userId but it returns null,
this is the subscription:
subscription
and this is the publish in backend:
publish
and the log show null for userId:
console
Already check if user is logged, I mean the userId exist just can´t get it in the publish callback function


#2

I´ll appreciate any help you can give me, thnaks


#3

Try using Meteor.userId() to see if that works.
Also try console.dir(this) to see if it has everything it should have.
Where does the carnectBackend come from, but most importantly, what does it do? self.subscribe should be enough.


#4

Is it possible that the subscription is called from multiple places? It seems to be called twice


#5

Thanks for the answers, I think Meteor.userId() is not available on the backend is only for client, and cloudspider, I would check if subscription is calling from more than one place, but is that a problem? that affects in some way how userId is pass to the subscription?


#6

Hi,

Meteor.userId() very surely is available on the server if the user is logged in
But why are you using this.userId and not just Meteor.userId() (in the publish)?
That is not the same thing?

regards,

Paul


#7

Its not the same thing (dunno if this has changed already). Meteor.userId() is the ID coming from the clientside and is therefore not secure!

cloudspider, I would check if subscription is calling from more than one place, but is that a problem? that affects in some way how userId is pass to the subscription?

Yes it is a problem. You are properly checking if the userId exists before subscribing in this one. It might be that this check is not present on other places making you subcribe with no user.

Also you can try checking with Meteor.user() instead of Meteor.userId() since the user is then known for sure (user info has been published to the client)