How to check, could use `Meteor.userId()` or not on anywhere?

#1

How to check, could I use Meteor.userId() on not clear place?

// Try
if(Meteor.userId && Meteor.userId()){
}

But get

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

Please help me

#2

One is for server, the other one is for client: https://guide.meteor.com/accounts.html#userid-ddp - you don’t need to use both.

#3

I would like check it on Server, but I still get the same

// Create timestamp behaviours
class AppCollection extends Mongo.Collection {
  // Current user
  _getUserId() {
    return Meteor.isServer && Meteor.userId()
  }
  
  insert(....)

Get error when fixture run on startup

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

Please help me

#4

But it work fine when I logged in, and insert data from Form Input

#5

I don’t understand how to use, please example

#6

You need to explicitly add a userId parameter for your collection functions. Then inside the method calls or publications, you need to pass this.userId explicitly