Skip to content

returned user doc doesn't always include _id field when from cache #9

Description

@wildhart

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 have a PR to fix this nearly ready...

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions