Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wildhart opened this issue Jun 6, 2019 · 0 comments
Open

Comments

@wildhart
Copy link

wildhart commented Jun 6, 2019

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...

wildhart added a commit to wildhart/userCache that referenced this issue Jun 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant