发布自定义 Meteor.user() 字段 [英] Publishing custom Meteor.user() fields

查看:16
本文介绍了发布自定义 Meteor.user() 字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这个问题已经被问过很多次了,但我很难发布这些信息.

I know this question has been asked numerous times but I am having a difficult time publishing this information.

在 Accounts.onCreateUser 中,我添加了一个字段

In Accounts.onCreateUser I am adding a field like so

{
 ...
 user['info'] = { email: options.email, is_admin: false};
}

我发布此信息;

Meteor.publish('user', function() {
    return Meteor.users.find({}, { fields: { info: 1} });
}

Meteor.subscribe('user');

调试后,发布查询返回正确的信息,但当我尝试访问 Meteor.user() 时,该信息从未提供给客户端.我是否必须执行其他操作才能允许 Meteor.user() 访问信息?

After debugging the Publish query returns the correct information but that is never given to the client when I try to access Meteor.user(). Do I have to do something else to allow info to be access by Meteor.user()?

有什么建议吗?

推荐答案

您需要使用 null 向单个用户发布.

You'll want to use null to publish to the single user.

Meteor.publish(null, function() {
  return Meteor.users.find({_id: this.userId}, {fields: {info: 1}});
});

这篇关于发布自定义 Meteor.user() 字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆