Var userId = (Meteor.user()) ? Meteor.user()._id : null;

If I don’t do this any time I want to get the current logged in user I get a tone of errors in the console about Meteor.user()._id being undefined. I feel like I’m doing something wrong.

Hello,

You can use Meteor.userId()… “Get the current user id, or null if no user is logged in. A reactive data source.” http://docs.meteor.com/#/full/meteor_userid

It works anywhere but publish functions.

You can user this.userId in publish functions: http://docs.meteor.com/#/full/publish_userId

Meteor.userId() is a reactive shortcut for that and it won’t give you errors. Returns either the userId as a string, or null

http://docs.meteor.com/#/full/meteor_userid

Meteor.userId() Anywhere but publish functions
accounts-base/accounts_client.js, line 11
Get the current user id, or null if no user is logged in. A reactive data source.

1 Like