I've had instances where the returned user doc doesn't include the _id field.
This can cause a bug in code like this:
// toggle the 'flag' of user given by 'username', or the logged in user
const user = username
? Meteor.users.findOne({username}, {fields: {[flag]: 1}})
: Meteor.user(flag);
Meteor.users.update({id: user._id}, {$set: {[flag]: !user[flag]}});
Which fails if username is falsey and the cached Meteor.user() doesn't contain the _id field.
Obviously this is a contrived example which could easily be rewritten, but I did hit this bug and so userCache should be fixed to return the expected result consistent with the default Meteor.user().
I've had instances where the returned user doc doesn't include the
_id
field.This can cause a bug in code like this:
Which fails if
username
is falsey and the cached Meteor.user() doesn't contain the_id
field.Obviously this is a contrived example which could easily be rewritten, but I did hit this bug and so
userCache
should be fixed to return the expected result consistent with the defaultMeteor.user()
.I have a PR to fix this nearly ready...