Clean up users autopublish.

Users table suppresses private fields when autopublished. Current user published turned into automatic publish, so the warning about the autopublish package is suppressed.
This commit is contained in:
Nick Martin
2012-06-15 13:11:02 -07:00
parent 0b1708d9fc
commit 44751cebc5
3 changed files with 22 additions and 5 deletions

View File

@@ -33,5 +33,4 @@
});
};
Meteor.subscribe("currentUser");
})();

View File

@@ -1,11 +1,18 @@
Meteor.users = new Meteor.Collection("users");
if (!Meteor.accounts) {
Meteor.accounts = {};
}
// internal login tokens collection. Never published.
Meteor.accounts._loginTokens = new Meteor.Collection(
"accounts._loginTokens",
null /*manager*/,
null /*driver*/,
true /*preventAutopublish*/);
// Users table. Don't use the normal autopublish, since we want to hide
// some fields. Code to autopublish this is in accounts_server.js.
Meteor.users = new Meteor.Collection(
"users",
null /*manager*/,
null /*driver*/,
true /*preventAutopublish*/);

View File

@@ -110,15 +110,26 @@
}
});
// Publish a few attributes on the current user object
Meteor.publish("currentUser", function() {
// Always publish the current user's record to the client.
Meteor.publish(null, function() {
if (this.userId())
return Meteor.users.find({_id: this.userId()},
{fields: {services: 0, private: 0}});
else
return null;
}, {is_auto: true});
// If autopublish is on, also publish everyone else's user record.
Meteor.default_server.onAutopublish(function () {
var handler = function () {
return Meteor.users.find(
{}, {fields: {services: 0, private: 0, emails: 0}});
};
Meteor.default_server.publish(null, handler, {is_auto: true});
});
// Try all of the registered login handlers until one of them doesn't
// return `undefined`, meaning it handled this call to `login`. Return
// that return value.