使用Meteor.users.find()获取profile.name

时间:2016-01-08 13:42:35

标签: javascript mongodb meteor

我可以使用以下内容获取_idusername等常规字段:

users: function () {
      return Meteor.users.find({}, {fields:{_id:1,username:1}});
}

但如何获取来自Facebook / Google / Twitter的profile.name

1 个答案:

答案 0 :(得分:1)

使用http://docs.meteor.com/#/full/accounts_oncreateuser挂钩来编写profile.name

Accounts.onCreateUser(function(options, user) {
    // We still want the default hook's 'profile' behavior.
    if (options.profile) {
        user.profile = options.profile;
        user.profile.memberSince = new Date();

        // Copy data from Facebook to user object
        user.profile.facebookId = user.services.facebook.id;
        user.profile.firstName = user.services.facebook.first_name;
        user.profile.email = user.services.facebook.email;
        user.profile.link = user.services.facebook.link;
    }

    return user;
});

Getting Facebook Avatar in Meteor when Autopublish is removed