v1.7.0Published 3 years ago

This package has not had recent updates. Please investigate it's current state before committing to using it in your project.


A model for a user which contains useful methods and can be extended by other packages by extending it's prototype to add methods that add functionality that are pertinent to their purpose. For example the socialize:friendships package extends the user model to provide helpers which return friend requests and friends for the user.


User() - Extends BaseModel

User.prototype.displayName() - A representation of the user. "You" if the instance is the same as the current user, instance.username otherwise.

User.prototype.isSelf(user) - Checks if one user is another user by comparing _ids.

User.prototype.defaultEmail - Returns the first email address in the list of emails.

Q: Is there any documentation on the User Profile?

The basic user profile is structured like the following JSON document:

2  username: 'jdoe',  
3  emails: [{'address': '', 'verified': true}],   
4  profile: {
5    'name': 'Jane Doe'
6  }

The intention is that the first email address in the 'emails' list is the primary contact, where people want to be emailed, and the other addresses in the list are alternates that work for login but do not receive email.

Q: I'm having problems managing Meteor.users in my social app. Help?

The pattern for social apps involves two publications. One for yourself, and one for other people. You'll want something like the following:

1// Publish a person's own user profile to themselves
2Meteor.publish('userProfile', function (userId) {
3  return Meteor.users.find({_id: this.userId}, {fields: {
4    '_id': true,
5    'username': true,
6    'profile': true,
7    '': true,
8    'profile.avatar': true,
9    'profile.username': true,
11    'profile.favoriteColor': true,
12    'profile.selectedTheme': true,
14    'profile.address': true,
15    '': true,
16    'profile.state': true,
17    '': true,
19    'emails': true,
20    'emails[0].address': true,
21    'emails.address': true
22  }});
26// Publish the user directory which everbody can see
27Meteor.publish("usersDirectory", function () {
28  return Meteor.users.find({}, {fields: {
29    '_id': true,
30    'username': true,
31    'profile': true,
32    '': true,
33    'profile.avatar': true,
34    'profile.username': true,
36    'emails': true,
37    'emails[0].address': true,
38    'emails.address': true
39  }});

Note that the profile details, such as address and theme preferences will only be visible to an individual user, and won't be visible to people browsing the user directory.



MIT. Use as you will.