How to change DDP userId?

I creating custom accounts package and i need to set userId of DDP connection after login successful.

I using this method to do that:

Meteor.connection.setUserId(userId);

But i can’t use it in publishcation methods:

Meteor.publish('jobs', function(options){
    console.log(this.userId); // <= NULL
});

Anyone can help me?

1 Like

You have to call this.setUserId on server. See: https://github.com/gwendall/meteor-impersonate/

1 Like

Thankyou so much. Solved !